numpy字符串操作 |加入()函数
numpy.core.defchararray.join(sep, arr)
是另一个在 numpy 中进行字符串操作的函数。对于 arr 中的每个元素,它返回字符串的副本,其中数组的字符串元素已通过分隔符连接。
Parameters:
sep : It joins elements with the string between them.
arr :Input array.
Returns : Output array of str or unicode with joined elements.
代码#1:
# Python program explaining
# numpy.core.defchararray.join() method
# importing numpy
import numpy as geek
# input array
in_arr = geek.array(['Python', 'Numpy', 'Pandas'])
print ("Input original array : ", in_arr)
# creating the separator
sep = geek.array(['-', '+', '*'])
out_arr = geek.core.defchararray.join(sep, in_arr)
print ("Output joined array: ", out_arr)
输出:
Input original array : ['Python' 'Numpy' 'Pandas']
Output joined array: ['P-y-t-h-o-n' 'N+u+m+p+y' 'P*a*n*d*a*s']