The char.rfind() function in Python returns the highest index in an input array's string where the sub substring is found. This is such that the sub is contained within [start, end].
char.rfind(a, sub, start=0, end=None)
The char.rfind() function takes the following parameter values:
a: This is the input array. It is required.sub: This is the substring to be searched for. It is required.start, end: These are optional arguments interpreted as in slice notation.The char.rfind() function returns an output array of integers. It returns -1 if the sub is not found.
import numpy as np# creating an input arraya = np.array(['What', "makes you", "happy?"])# creating the substringsub = "ou"# implementing the char.rfind() functionmyarray = np.char.rfind(a, sub, start=1, end=None)# printing the input arrayprint(a)# printing the output arraysprint(myarray)
numpy module.a using the array() function.sub.char.rfind() function on the input array. The result is assigned to a variable myarray.a.myarray.Notice from the code output that the substring"ou"can be found in the array's third element. Its index position in the element is7.