Write a NumPy program to count a given word in each row of a given array of string values
- برمجة بايثون
- 2021-09-13
- mhanasmh00489829403
الأجوبة
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]]
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال