Q:

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

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now