What is the numpy.char.rpartition() function in Python?
Overview
In Python, the char.rpartition() is used to split each element of an array of strings around the right-most separator.
Syntax
char.rpartition(a, sep)
Parameter value
This function takes the following parameter values:
a: This is the input array of strings or Unicode.sep: This is the right-most separator to split each element in the given array.
Return value
This function returns an array of strings or unicode, depending on the input type in the function.
import numpy as np# creating the input arraya = np.array(["Hi what are your doing?"])# creating seperator charactersep = "your"# implementing the char.rpartition() functionprint(np.char.rpartition(a, sep))
Explanation
- Line 1: We import the
numpymodule. - Line 4: We use the
array()function to create an array of stringsmyarray. - Line 7: We create a separator variable
septhat we use to partition the elements in the array. - Line 10: We implement the
char.rpartition()function on the variablesmyarrayandsep. Next, we obtain and print the result.