Monday, November 30, 2015

Unique Values from NumPy Array

Here is a quick example of how to get a unique value list from a numpy array.
from __future__ import print_function
import numpy as np

values = [['a', 'b', 'c'],
          ['e', 'b', 'd'],
          ['a', 'b', 'c']]
np_array = np.array(values)
print (np.unique(np_array[:,1], return_index=False))

# should see: ['b']

Enjoy!

No comments: