Numpy string operations | rpartition() function
Last Updated :
29 Aug, 2020
In the numpy.core.defchararray.rpartition() function, each element in arr, split the element as the last occurrence of sep, and return 3 strings containing the part before the separator, the separator itself, and the part after the separator. If the separator is not found, return 3 strings containing the string itself, followed by two empty strings.
Syntax : numpy.core.defchararray.rpartition(arr, sep)
Parameters :
arr : [array_like, {str, unicode}] Given Input array.
sep : [str or unicode] Right-most separator to split each element in array.
Return : [ndarray] Return the output array of str or unicode, depending on input type
Code #1 :
Python3
import numpy as geek
arr = "GeeksforGeeks - A computer science portal for geeks"
sep = 'None'
gfg = geek.char.rpartition(arr, sep)
print (gfg)
|
Output :
[” ” ‘GeeksforGeeks – A computer science portal for geeks’]
Code #2 :
Python3
import numpy as geek
arr = "GeeksforGeeks - A computer science portal for geeks"
sep = 'science'
gfg = geek.char.rpartition(arr, sep)
print (gfg)
|
Output :
[‘GeeksforGeeks – A computer ‘ ‘science’ ‘ portal for geeks’]
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...