how to find unique values in numpy array

Solutions on MaxInterview for how to find unique values in numpy array by the best coders in the world

showing results for - "how to find unique values in numpy array"
Julián
15 Jun 2017
1number_list = numpy.array([1, 1, 2, 3, 4, 4, 1])
2(unique, counts) = numpy.unique(number_list, return_counts=True)
Colleen
09 Jun 2019
1>>> a = np.array(['a', 'b', 'b', 'c', 'a'])
2>>> u, indices = np.unique(a, return_index=True)
3>>> u
4array(['a', 'b', 'c'], dtype='<U1')
5>>> indices
6array([0, 1, 3])
7>>> a[indices]
8array(['a', 'b', 'c'], dtype='<U1')
9
Adriana
28 May 2018
1>>> a = np.array([1, 2, 6, 4, 2, 3, 2])
2>>> values, counts = np.unique(a, return_counts=True)
3>>> values
4array([1, 2, 3, 4, 6])
5>>> counts
6array([1, 3, 1, 1, 1])
7>>> np.repeat(values, counts)
8array([1, 2, 2, 2, 3, 4, 6])    # original order not preserved
9
Tadhg
02 Oct 2016
1>>> a = np.array([1, 2, 6, 4, 2, 3, 2])
2>>> u, indices = np.unique(a, return_inverse=True)
3>>> u
4array([1, 2, 3, 4, 6])
5>>> indices
6array([0, 1, 4, 3, 1, 2, 1])
7>>> u[indices]
8array([1, 2, 6, 4, 2, 3, 2])
9
Federico
09 Mar 2016
1>>> a = np.array([[1, 0, 0], [1, 0, 0], [2, 3, 4]])
2>>> np.unique(a, axis=0)
3array([[1, 0, 0], [2, 3, 4]])
4
Serena
15 Apr 2016
1>>> np.unique([1, 1, 2, 2, 3, 3])
2array([1, 2, 3])
3>>> a = np.array([[1, 1], [2, 3]])
4>>> np.unique(a)
5array([1, 2, 3])
6
queries leading to this page
numpy array unique valuesfind unique values numpyhow to get unique values in numpy arraycount unique values numpynumpy count unique in arrayget unique values from numpy list pythonpython count unique values in a matrixunique numpy countnp array unique counthow to get unique values in np arraynumpy array number of unique elementunique function in numpy in pythonhow to calculate unique values in np arrayunique values in a numpy arraycount unique value in array npnumpy count unique valuesnumpy find unique valuesnumpy unique countunique values in numpy arrayunique values count numpynumpy uniquenumpy keep unique elementesnumpy unique return all indicesnumpy where and uniquecount unique values in list python using numpyunique from np arraygetting number of unique value in python arraynumpy uniquernumpy array unique countunique values of numpy arraycount unique value in list python using numpyunique values of np arrayunique values of a numpy arraynumpy array count unique valuescount unique values in numpy arraycount distinct values numpy arrayfind unique rows numpyfind uniques rows numpymatrix array get unique values pythonget unique values numpyhow to get count of unique values in numpy arrayunique elements in array numpynumpy count unique column wisehow to find unique values in a numpy arrayget unique value in numpy arraynumpy array unique countsget unique counts python numpycount uniques numpyhow to find unique values in nd arrayunique values from numpy arraycount number of unique elements in numpy arraynumpy unique valuesnp unique with countuniquevalues in numpy arraynumpy count unique values in arrayunique from numpy array of array pythonnumpy unique from arrayfind unique values in a numpy arrayhow to find unique values in numpy arrayunique counts numpycont unique values numpynumpy print the number of unique elementsprint unique values in np arraynumpy unique rowsmatrix arrays get unique values pythonnumpy get unique rowshow to find unique values in an array pythonunique values numpynumpy unique value countshow to find the unique values of a column in numpy arraynp count uniquehow i check all unique value in ndarrayfind unique values in numpy arrayunique values in np arrayunique value in np arraynumber of unique values numpynumpy count unique elementscount unique numpy arraynumpy array uniqueprint unique values numpyhow to get the count the number of unique values in numpyhow to count unique values in numpy arrayget unique values from numpy array pythonunique values numpy arrayunique value of numpy arraynumber of unique values in array numpyunique elements in numpy arrayunique 2b np arrayhow to get the count of unique values in numpynumpy where uniquefind unique elements in numpy arrayunique value count in np arrayhow to allow unique value in numpy arraynumpy ndarray count unique valuesnumpy array get unique valueshow to get unique values from numpy arrayfrequency of unique values in a numpy arrayndarray count unique valuesnumpy array get all unique valuesget unique values from numpy arraycheck unique values in numpy arraynumpy array count of unique elementsnumpy count unique in row in arrayunique value in ndarraychecking all unique in an numpy arraynp array count unique valuesget all unique values in numpy arraynumpy count uniqueunique values of numpy array pythonnumpy ndarray print unique valuescount unique values numpy arrayhow to print unique values in a numpy arraynumpy count number of unique elementshow to get unique elements from a numpy array in pythonnumpy count unique values in columncount unique value in python using numpynp unique countnumpy get unique valuesunique value counts numpy arraynumpy array unique value countshow to find unique values in numpy array