Get the count the frequency of unique values from the NumPy array

In this python numpy program, we will count the frequency of unique values from the NumPy array.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Get the unique values and their frequency from the array using np.unique(array,return_counts=True).
  4. Print the output.
				
					import numpy as np
x = np.array([8, 6, 7, 0, 7, 8, 6, 6])

unique, count = np.unique(x, return_counts=True)
print("Frequency of unique values in the given array:")
print(np.asarray((unique, count)))
				
			

Output :

				
					Frequency of unique values in the given array:
[[0 6 7 8]
 [1 3 2 2]]
				
			

get the magnitude of a vector.

check whether an array is empty.

Leave a Comment