count unique values numpy
number_list = numpy.array([1, 1, 2, 3, 4, 4, 1])
(unique, counts) = numpy.unique(number_list, return_counts=True)
count unique values numpy
number_list = numpy.array([1, 1, 2, 3, 4, 4, 1])
(unique, counts) = numpy.unique(number_list, return_counts=True)
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])
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])
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us