Write a NumPy program to count a given word in each row of a given array of string values.
import numpy as np str1 = np.array([['Python','NumPy','Exercises'], ['Python','Pandas','Exercises'], ['Python','Machine learning','Python']]) print("Original array of string values:") print(str1) print("\nCount 'Python' row wise in the above array of string values:") print(np.char.count(str1, 'Python'))
Sample Output:
Original array of string values: [['Python' 'NumPy' 'Exercises'] ['Python' 'Pandas' 'Exercises'] ['Python' 'Machine learning' 'Python']] Count 'Python' row wise in the above array of string values: [[1 0 0] [1 0 0] [1 0 1]]
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer