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 unique Example Get the unique rows and columns

# welcome to softhunt.net
import numpy as np

# Creating 2D Array
duplicate_array_2d = np.array([[2,2,1],[4,5,5],[2,5,5]])

print('2D array:
', duplicate_array_2d)

# GET UNIQUE ROWS
unique_rows  = np.unique(duplicate_array_2d, axis = 0)
print('Unique rows: 
', unique_rows)

# GET UNIQUE COLUMNS
unique_columns  = np.unique(duplicate_array_2d, axis = 1)
print('Unique columns: 
', unique_columns)
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 :: import xgboost 
Python :: python write to command prompt 
Python :: how to wait in python 
Python :: discord.py make command admin only 
Python :: print json python 
Python :: tensorflow history plot 
Python :: how to create a keylogger in python 
Python :: perfect number in python 
Python :: pandas insert column in the beginning 
Python :: bee movie script 
Python :: if type is string python 
Python :: python half of string 
Python :: numpy mean 2 arrays 
Python :: python - give a name to index column 
Python :: np array n same values 
Python :: combination python 
Python :: Exception: ROM is missing for space_invaders, see https://github.com/openai/atari-py#roms for instructions site:stackoverflow.com 
Python :: python roman to integer 
Python :: python infinite value 
Python :: split a path into all subpaths 
Python :: pandas.core.indexes.base.index to list 
Python :: python sendmessage whatsapp 
Python :: pandas remove row if missing value in column 
Python :: py get mouse coordinates 
Python :: how to add static files in django 
Python :: matplotlib insert text 
Python :: extract numbers from string python 
Python :: dataframe select entries that are in a list 
Python :: next prime number in python 
Python :: ckeditor django 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =