In [1]:
import numpy as np
In [2]:
a = np.array([0, 0, 30, 10, 10, 20])
print(a)
In [3]:
print(np.unique(a))
In [4]:
print(type(np.unique(a)))
In [5]:
l = [0, 0, 30, 10, 10, 20]
print(l)
In [6]:
print(np.unique(l))
In [7]:
print(type(np.unique(l)))
In [8]:
print(np.unique(a).size)
In [9]:
print(len(np.unique(a)))
In [10]:
u, counts = np.unique(a, return_counts=True)
print(u)
In [11]:
print(counts)
In [12]:
print(u[counts == 1])
In [13]:
print(u[counts != 1])
In [14]:
print(np.unique(a, return_counts=True))
In [15]:
print(type(np.unique(a, return_counts=True)))
In [16]:
u, indices = np.unique(a, return_index=True)
print(u)
In [17]:
print(indices)
In [18]:
print(a)
In [19]:
print(a[indices])
In [20]:
u, inverse = np.unique(a, return_inverse=True)
print(u)
In [21]:
print(inverse)
In [22]:
print(a)
In [23]:
print(u[inverse])
In [24]:
u, indices, inverse, counts = np.unique(a, return_index=True, return_inverse=True, return_counts=True)
print(u)
In [25]:
print(indices)
In [26]:
print(inverse)
In [27]:
print(counts)
In [28]:
print(np.unique(a, return_counts=True, return_index=True, return_inverse=True))
In [29]:
a_2d = np.array([[20, 20, 10, 10], [0, 0, 10, 30], [20, 20, 10, 10]])
print(a_2d)
In [30]:
print(np.unique(a_2d))
In [31]:
print(np.unique(a_2d, axis=0))
In [32]:
print(np.unique(a_2d, axis=1))
In [33]:
print(a_2d[0])
In [34]:
print(np.unique(a_2d[0]))
In [35]:
print(a_2d[:, 2])
In [36]:
print(np.unique(a_2d[:, 2]))
In [37]:
print([np.unique(row) for row in a_2d])
In [38]:
print([np.unique(row).tolist() for row in a_2d])
In [39]:
print([np.unique(row).size for row in a_2d])
In [40]:
print(a_2d.T)
In [41]:
print([np.unique(row) for row in a_2d.T])
In [42]:
print(a_2d.shape)
In [43]:
print([np.unique(a_2d[:, i]) for i in range(a_2d.shape[1])])
In [44]:
u, indices, inverse, counts = np.unique(a_2d, return_index=True, return_inverse=True, return_counts=True)
print(u)
In [45]:
print(indices)
In [46]:
print(a_2d.flatten())
In [47]:
print(a_2d.flatten()[indices])
In [48]:
print(inverse)
In [49]:
print(u[inverse])
In [50]:
print(u[inverse].reshape(a_2d.shape))
In [51]:
print(counts)
In [52]:
u, indices, inverse, counts = np.unique(a_2d, axis=0, return_index=True, return_inverse=True, return_counts=True)
print(u)
In [53]:
print(indices)
In [54]:
print(a_2d[indices])
In [55]:
print(inverse)
In [56]:
print(u[inverse])
In [57]:
print(counts)
In [58]:
print(a_2d)
In [59]:
u, indices = np.unique(a_2d, return_index=True)
print(u)
In [60]:
print(a_2d.flatten())
In [61]:
print(indices)
In [62]:
print(list(zip(*np.where(a_2d == 0))))
In [63]:
d = {u: list(zip(*np.where(a_2d == u))) for u in np.unique(a_2d)}
print(d)
In [64]:
print(d[0])
In [65]:
print(d[10])
In [66]:
print(d[20])
In [67]:
print(d[30])
In [68]:
d = {u: list(zip(*np.where(a_2d == u)))
for u, c in zip(*np.unique(a_2d, return_counts=True)) if c == 1}
print(d)
In [69]:
d = {u: list(zip(*np.where(a_2d == u)))
for u, c in zip(*np.unique(a_2d, return_counts=True)) if c <= 2}
print(d)