takachanbo
takachanbo

Reputation: 683

Finding what elements are in a 2-D array

I'm trying to find what elements are in a 2-D array, such as something along the lines below:

import numpy as np
a = np.array([[1,0,0],[1,3,0],[2,7,4]])
print find_element(a)
[0,1,2,3,4,7]

Is there a function that would do this for me?

Upvotes: 0

Views: 52

Answers (1)

DSM
DSM

Reputation: 353499

You could use np.unique:

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

Upvotes: 4

Related Questions