MCPcopy Create free account
hub / github.com/numpy/numpy / index

Function index

numpy/core/defchararray.py:785–816  ·  view source on GitHub ↗

Like `find`, but raises `ValueError` when the substring is not found. Calls `str.index` element-wise. Parameters ---------- a : array_like of str or unicode sub : str or unicode start, end : int, optional Returns ------- out : ndarray Output arra

(a, sub, start=0, end=None)

Source from the content-addressed store, hash-verified

783
784@array_function_dispatch(_count_dispatcher)
785def index(a, sub, start=0, end=None):
786 """
787 Like `find`, but raises `ValueError` when the substring is not found.
788
789 Calls `str.index` element-wise.
790
791 Parameters
792 ----------
793 a : array_like of str or unicode
794
795 sub : str or unicode
796
797 start, end : int, optional
798
799 Returns
800 -------
801 out : ndarray
802 Output array of ints. Returns -1 if `sub` is not found.
803
804 See Also
805 --------
806 find, str.find
807
808 Examples
809 --------
810 >>> a = np.array(["Computer Science"])
811 >>> np.char.index(a, "Science", start=0, end=None)
812 array([9])
813
814 """
815 return _vec_string(
816 a, int_, 'index', [sub, start] + _clean_args(end))
817
818
819@array_function_dispatch(_unary_op_dispatcher)

Callers 1

indexMethod · 0.85

Calls 2

_vec_stringFunction · 0.90
_clean_argsFunction · 0.85

Tested by

no test coverage detected