{"id":8297,"date":"2023-11-03T08:19:26","date_gmt":"2023-11-03T02:49:26","guid":{"rendered":"https:\/\/python-programs.com\/?p=8297"},"modified":"2023-11-10T12:14:02","modified_gmt":"2023-11-10T06:44:02","slug":"python-find-unique-values-in-a-numpy-array-with-frequency-and-indices","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-find-unique-values-in-a-numpy-array-with-frequency-and-indices\/","title":{"rendered":"Python: Find Unique Values in a Numpy Array With Frequency and Indices"},"content":{"rendered":"

Methods to find unique values in a numpy array with frequency and indices<\/h2>\n

In this article, we will discuss how to find unique values, rows, and columns in a 1D & 2D Numpy array. Before going to the methods first we see numpy.unique() method because this method is going to be used.<\/p>\n

numpy.unique() method<\/h3>\n

numpy.unique() method help us to get the unique() values from given array.<\/p>\n

syntax:numpy.<\/span>unique<\/span>(<\/span>array, return_index=<\/span>False<\/span>, return_inverse=<\/span>False<\/span>, return_counts=<\/span>False<\/span>, axis=<\/span>None<\/span>)<\/span><\/code><\/p>\n

Parameters<\/h3>\n
    \n
  1. array-Here we have to pass our array from which we want to get unique value.<\/li>\n
  2. return_index- If this parameter is true then it will return the array of the index of the first occurrence of each unique value. By default it is false.<\/li>\n
  3. return_counts-If this parameter is true then it will return the array of the count of the occurrence of each unique value. By default it is false.<\/li>\n
  4. axis- It is used in the case of nd array, not in 1d array. axis=1 means we have to do operation column-wise and axis=0 means we have to do operation row-wise.<\/li>\n<\/ol>\n

    Now we will see different methods to find unique value with their indices and frequencies in a numpy array.<\/p>\n

    case 1-When our array is 1-D<\/h3>\n