Numpy str_len() function
Last Updated :
05 May, 2020
numpy.char.str_len(arr)
function is used for doing string operations in numpy. It returns the length of every string element wise.
Parameters:
arr : array_like of str or unicode.Input array.
Returns : [ndarray] Output Array of integer.
Code #1 :
import numpy as geek
in_arr = geek.array([ 'geeks for geeks' ])
print ( "Input array : " , in_arr)
out_arr = geek.char.str_len(in_arr)
print ( "Output array containing length: " , out_arr)
|
Output:
Input array : ['geeks for geeks']
Output array containing length: [15]
Code #2 :
import numpy as geek
in_arr = geek.array([ 'Numpy' , 'Python' , 'Pandas' ])
print ( "Input array : " , in_arr)
out_arr = geek.char.str_len(in_arr)
print ( "Output array containing length: " , out_arr)
|
Output:
Input array : ['Numpy' 'Python' 'Pandas']
Output array containing length: [5 6 6]
Share your thoughts in the comments
Please Login to comment...