Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

NumPy: rindex() function

numpy.core.defchararray.rindex() function

The numpy.core.defchararray.rindex() function raises ValueError when the substring sub is not found.
Calls str.rindex element-wise.

Syntax:

numpy.core.defchararray.rindex(a, sub, start=0, end=None)

Parameter:

Name Description Required /
Optional
a: array_like of str or unicode Input an array_like of string or unicode. Required
sub: str or unicode Input string or unicode. Required
start, end: int optional

Return value:

out : ndarray - Output array of ints.

Note:

The 'chararray' class exists for backwards compatibility with Numarray, it is not recommended for new development. Starting from numpy 1.4, if one needs arrays of strings, it is recommended to use arrays of 'dtype' 'object_', 'string_' or 'unicode_', and use the free functions in the 'numpy.char' module for fast vectorized string operations.

Some methods will only be available if the corresponding string method is available in your version of Python.

The preferred alias for 'defchararray' is 'numpy.char'.

Example: numpy.rindex() function

>>> import numpy as np
>>> x = np.char.rindex('the quick brown fox', 'fox', start=0, end=None)
>>> x
array(16)

Pictorial Presentation:

NumPy String operation: rindex() function

Example: numpy.rindex() function

>>> import numpy as np
>>> y = np.char.rindex('the quick brown fox jumps over the lazy dog', 'over the lazy dog', start=0, end=None)
>>> y
array(26)

Pictorial Presentation:

NumPy String operation: rindex() function

Python - NumPy Code Editor:

Previous: rfind()
Next: startswith()