Create a 2-dimensional array of size 2 x 3, composed of 4-byte integer elements. Write a NumPy program to find the number of occurrences of a sequence in the said array

  • برمجة بايثون

Create a 2-dimensional array of size 2 x 3, composed of 4-byte integer elements. Write a NumPy program to find the number of occurrences of a sequence in the said array.

الأجوبة

import numpy as np
np_array = np.array([[1, 2, 3], [2, 1, 2]], np.int32)
print("Original Numpy array:")
print(np_array)
print("Type: ",type(np_array))
print("Sequence: 1,2",)
result = repr(np_array).count("1, 2")
print("Number of occurrences of the said sequence:",result)

Sample Output:

Original Numpy array:
[[1 2 3]
 [2 1 2]]
Type:  <class 'numpy.ndarray'>
Sequence: 1,2
Number of occurrences of the said sequence: 2
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...