Q:

Write a NumPy program to find the most frequent value in an array

0

Write a NumPy program to find the most frequent value in an array.

All Answers

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

import numpy as np
x = np.random.randint(0, 10, 40)
print("Original array:")
print(x)
print("Most frequent value in the above array:")
print(np.bincount(x).argmax())

Sample Output:

Original array:                                                        
[4 7 3 8 4 8 6 3 1 8 6 3 3 9 7 8 3 3 0 6 8 3 1 8 2 2 9 7 8 9 8 5 9 6 8 
5 3                                                                    
 8 9 1]                                                                
Most frequent value in the above array:                                
8

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