Numpy字符串操作 | rpartition()函数
在numpy.core.defchararray.rpartition()函数中,arr 中的每个元素,将元素拆分为最后一次出现的 sep,并返回包含分隔符之前的部分、分隔符本身和分隔符之后的部分的 3 个字符串。如果没有找到分隔符,则返回包含字符串本身的 3 个字符串,后跟两个空字符串。
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
代码#1:
Python3
# Python program explaining
# numpy.char.rpartition() function
# importing numpy as geek
import numpy as geek
arr = "GeeksforGeeks - A computer science portal for geeks"
sep = 'None'
gfg = geek.char.rpartition(arr, sep)
print (gfg)
Python3
# Python program explaining
# numpy.char.rpartition() function
# importing numpy as geek
import numpy as geek
arr = "GeeksforGeeks - A computer science portal for geeks"
sep = 'science'
gfg = geek.char.rpartition(arr, sep)
print (gfg)
输出 :
[” ” ‘GeeksforGeeks – A computer science portal for geeks’]
代码#2:
Python3
# Python program explaining
# numpy.char.rpartition() function
# importing numpy as geek
import numpy as geek
arr = "GeeksforGeeks - A computer science portal for geeks"
sep = 'science'
gfg = geek.char.rpartition(arr, sep)
print (gfg)
输出 :
[‘GeeksforGeeks – A computer ‘ ‘science’ ‘ portal for geeks’]