numpy str_len()函数
numpy.char.str_len(arr)
函数用于在 numpy 中进行字符串操作。它明智地返回每个字符串元素的长度。
Parameters:
arr : array_like of str or unicode.Input array.
Returns : [ndarray] Output Array of integer.
代码#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]