Numpy str_len() function

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 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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) 

chevron_right


Output:

Input array :  ['geeks for geeks']
Output array containing length:  [15]

 

Code #2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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) 

chevron_right


Output:

Input array :  ['Numpy' 'Python' 'Pandas']
Output array containing length:  [5 6 6]
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.