Numpy str_len()函数
numpy.char.str_len(arr)函数用于在numpy中进行字符串操作。它返回每个字符串元素的长度。
参数:
arr : array_like of str或unicode。输入数组。
返回: [ndarray] 输出整数阵列。
代码#1:
# Python program explaining
# numpy.char.str_len() method
# importing numpy
import numpy as geek
# input array
in_arr = geek.array(['geeks for geeks'])
print ("Input array : ", in_arr)
# output array
out_arr = geek.char.str_len(in_arr)
print ("Output array containing length: ", out_arr)
输出:
Input array : ['geeks for geeks']
Output array containing length: [15]
代码#2:
# Python program explaining
# numpy.char.str_len() method
# importing numpy
import numpy as geek
# input array
in_arr = geek.array(['Numpy', 'Python', 'Pandas'])
print ("Input array : ", in_arr)
# output array
out_arr = geek.char.str_len(in_arr)
print ("Output array containing length: ", out_arr)
输出:
Input array : ['Numpy' 'Python' 'Pandas']
Output array containing length: [5 6 6]