Q:

Write a NumPy program to count the frequency of unique values in numpy array

0

Write a NumPy program to count the frequency of unique values in numpy array.

All Answers

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

import numpy as np
a = np.array( [10,10,20,10,20,20,20,30, 30,50,40,40] )
print("Original array:")
print(a)
unique_elements, counts_elements = np.unique(a, return_counts=True)
print("Frequency of unique values of the said array:")
print(np.asarray((unique_elements, counts_elements)))

Sample Output:

Original array:                                                        
[10 10 20 10 20 20 20 30 30 50 40 40]                                  
Frequency of unique values of the said array:                          
[[10 20 30 40 50]                                                      
 [ 3  4  2  2  1]]

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