Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

count unique values numpy

number_list = numpy.array([1, 1, 2, 3, 4, 4, 1])
(unique, counts) = numpy.unique(number_list, return_counts=True)
Comment

how to find unique values in numpy array

>>> a = np.array([1, 2, 6, 4, 2, 3, 2])
>>> u, indices = np.unique(a, return_inverse=True)
>>> u
array([1, 2, 3, 4, 6])
>>> indices
array([0, 1, 4, 3, 1, 2, 1])
>>> u[indices]
array([1, 2, 6, 4, 2, 3, 2])
Comment

how to find unique values in numpy array

>>> a = np.array([1, 2, 6, 4, 2, 3, 2])
>>> values, counts = np.unique(a, return_counts=True)
>>> values
array([1, 2, 3, 4, 6])
>>> counts
array([1, 3, 1, 1, 1])
>>> np.repeat(values, counts)
array([1, 2, 2, 2, 3, 4, 6])    # original order not preserved
Comment

NumPy unique Example Get the counts of each unique value

# welcome to softhunt.net
import numpy as np

duplicates = np.array([2,3,3,4,5,5,1,5,4,6,7,5,1,5,3,5,1,3])

# GET UNIQUE VALUES
ans = np.unique(duplicates, return_counts = True)
print(ans)
Comment

numpy array unique value counts

import numpy as np

x = np.array([1,1,1,2,2,2,5,25,1,1])
unique, counts = np.unique(x, return_counts=True)

print np.asarray((unique, counts)).T
Comment

how to find unique values in numpy array

>>> a = np.array([[1, 0, 0], [1, 0, 0], [2, 3, 4]])
>>> np.unique(a, axis=0)
array([[1, 0, 0], [2, 3, 4]])
Comment

how to find unique values in numpy array

>>> a = np.array(['a', 'b', 'b', 'c', 'a'])
>>> u, indices = np.unique(a, return_index=True)
>>> u
array(['a', 'b', 'c'], dtype='<U1')
>>> indices
array([0, 1, 3])
>>> a[indices]
array(['a', 'b', 'c'], dtype='<U1')
Comment

NumPy unique Example Get unique values from a 1D Numpy array

# welcome to softhunt.net
import numpy as np

duplicates = np.array([2,3,3,4,5,5,1,5,4,6,7,5,1,5,3,5,1,3])

# GET UNIQUE VALUES
ans = np.unique(duplicates)
print(ans)
Comment

how to find unique values in numpy array

>>> np.unique([1, 1, 2, 2, 3, 3])
array([1, 2, 3])
>>> a = np.array([[1, 1], [2, 3]])
>>> np.unique(a)
array([1, 2, 3])
Comment

PREVIOUS NEXT
Code Example
Python :: closing a file in python 
Python :: convert to datetime object 
Python :: udp socket python 
Python :: how to add a value to a list in python 
Python :: basic script 
Python :: python exception 
Python :: huggingface dataset from pandas 
Python :: how to create an array in python 
Python :: for in python 
Python :: how to check dimension of array in python 
Python :: fetch data from excel in python 
Python :: python if string contains substring 
Python :: pathlib path of current file 
Python :: generate random integers in a range python 
Python :: maximum and minimum value of array python 
Python :: import all csv as append dataframes python 
Python :: convert xls to xlsx python 
Python :: how to raise the exception in __exit__ python 
Python :: python request coinmarketcap 
Python :: ffmpeg python video from images 
Python :: simple jwt 
Python :: remove leading and lagging spaces dataframe python 
Python :: python - regexp to find part of an email address 
Python :: insert column in a dataframe 
Python :: termcolor print python 
Python :: Python Tkinter Text Widget Syntax 
Python :: Write Python programs to print numbers from 1 to 10000 while loops 
Python :: longest common subsequence python 
Python :: python print n numbers 
Python :: python split by first match 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =