Answers for "numpy array unique count"

5

count unique values numpy

number_list = numpy.array([1, 1, 2, 3, 4, 4, 1])
(unique, counts) = numpy.unique(number_list, return_counts=True)
Posted by: Guest on June-20-2021
3

python unique array of array numpy

>>> import numpy as np
>>> x = np.array([[1, 1], [2,3], [3,4]])
>>> np.unique(x)
array([1, 2, 3, 4])
Posted by: Guest on April-29-2021
0

return position of a unique value in python array

In [304]: array = np.array([1, 1, 2, 3, 2, 1, 2, 3])

In [305]: np.unique(array)            # unique values in `array`
Out[305]: array([1, 2, 3])

In [306]: array == 1                  # retrieve a boolean mask where elements are equal to 1
Out[306]: array([ True,  True, False, False, False,  True, False, False])

In [307]: (array == 1).nonzero()[0]   # get the `True` indices for the operation above
Out[307]: array([0, 1, 5])
Posted by: Guest on April-27-2020

Code answers related to "numpy array unique count"

Python Answers by Framework

Browse Popular Code Answers by Language