You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
----> 1 np.unique(a)
<__array_function__ internals> in unique(*args, **kwargs)
~/miniconda3/lib/python3.7/site-packages/numpy/lib/arraysetops.py in unique(ar, return_index, return_inverse, return_counts, axis)
260 ar = np.asanyarray(ar)
261 if axis is None:
--> 262 ret = _unique1d(ar, return_index, return_inverse, return_counts)
263 return _unpack_tuple(ret)
264
~/miniconda3/lib/python3.7/site-packages/numpy/lib/arraysetops.py in _unique1d(ar, return_index, return_inverse, return_counts)
308 aux = ar[perm]
309 else:
--> 310 ar.sort()
311 aux = ar
312 mask = np.empty(aux.shape, dtype=np.bool_)
TypeError: '<' not supported between instances of 'str' and 'int'
Numpy/Python version information:
1.18.0 3.7.5 (default, Oct 25 2019, 10:52:18)
[Clang 4.0.1 (tags/RELEASE_401/final)]
The text was updated successfully, but these errors were encountered:
Since the docstring of unique states "Returns the sorted unique elements of an array", I think this is a "can't fix": we cannot sort a mixture of strings and integers.
Object arrays are supported as long as the underlying objects are well behaved. In many cases object arrays work, but in this instance it does not. A set might be better suited to your use case: set([1, 1, 1, 'a', 'b']) -> set(['a', 1, 'b'])
@Jerevia, thanks for reporting the issue. This issue is a duplicate of #641, so I'm closing it. Further discussion should be continued in the old issue, which is still open.
Getting a
TypeError
while usingnp.unique
with array ofdtype=object
Reproducing code example:
Error message:
Numpy/Python version information:
1.18.0 3.7.5 (default, Oct 25 2019, 10:52:18)
[Clang 4.0.1 (tags/RELEASE_401/final)]
The text was updated successfully, but these errors were encountered: