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)
| 783 | |
| 784 | @array_function_dispatch(_count_dispatcher) |
| 785 | def 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) |
no test coverage detected