The char.str_len()
function in Python is used to return the length element-wise. In other words, it is used to obtain the string length of each element of an array.
char.str_len(a)
The char.str_len()
function takes a single parameter value, a
, which represents the input array of strings.
The char.str_len()
function returns an output array of integers.
Let's look at the code below:
import numpy as np# creating the input arraymyarray = np.array(["Theo", "10", "Numpy", "YES", "1", "and"])# printing the input arrayprint(myarray)# implementing the char.str_len() functionprint(np.char.str_len(myarray))
numpy
module.myarray
, using the array()
function.myarray
.char.str_len()
function on the input array. We obtain and print the result to the console.