

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find the length of each string element in the Numpy array in C++
Here we will see how to get the length of each string element in the Numpy Array. Numpy is a library for Numeric Python, and it has very powerful array class. Using this we can store data in an array like structure. To get the length we can follow two different approach, these are like below −
Example
import numpy as np str_arr = np.array(['Hello', 'Computer', 'Mobile', 'Language', 'Programming', 'Python']) print('The array is like: ', str_arr) len_check = np.vectorize(len) len_arr = len_check(str_arr) print('Respective lengts: ', len_arr)
Output
The array is like: ['Hello' 'Computer' 'Mobile' 'Language' 'Programming' 'Python'] Respective lengts: [ 5 8 6 8 11 6]
Another approach using loop
Example
import numpy as np str_arr = np.array(['Hello', 'Computer', 'Mobile', 'Language', 'Programming', 'Python']) print('The array is like: ', str_arr) len_arr = [len(i) for i in str_arr] print('Respective lengts: ', len_arr)
Output
The array is like: ['Hello' 'Computer' 'Mobile' 'Language' 'Programming' 'Python'] Respective lengts: [5, 8, 6, 8, 11, 6]
- Related Questions & Answers
- Return each element of the masked array rounded in Numpy
- Cube each element in a Numpy array
- Return the length of the masked array in Numpy
- Return the length of a string array element-wise in Python
- Return each element of the masked array rounded to the nearest given number of decimals in NumPy
- For each element in a Numpy array, return a copy with the leading characters removed in Numpy
- Find Surpasser Count of each element in array in C++
- Return an array with the elements of a Numpy array right-justified in a string of length width
- Return an array with the elements of an array left-justified in a string of length width in Numpy
- Return a copy of an array with only the first character of each element capitalized in Numpy
- Remove axes of length one from the masked array in Numpy
- Write a Golang program to find the frequency of each element in an array
- Return the ceil of a specific array element in Numpy
- Return the floor of a specific array element in Numpy
- Python - Find the length of the last word in a string
Advertisements