I have a short example script:
import numpy as np
print('numpy version: ', np.version.version)
foo = np.full(10, 5)
bar = np.full(10, np.nan)
print('foo: ', foo)
print('Unique values of foo:', np.unique(foo))
print('bar: ', bar)
print('Unique values of bar:', np.unique(bar))
It prints the following result:
numpy version: 1.16.4
foo: [5 5 5 5 5 5 5 5 5 5]
Unique values of foo: [5]
bar: [nan nan nan nan nan nan nan nan nan nan]
Unique values of bar: [nan nan nan nan nan nan nan nan nan nan]
My questions:
- Why doesn't
np.unique()return just a singlenanvalue when it receivesbaras input? Surely this is an error, right? Or if it's the correct, expected behavior, then why is it correct? - What is the recommended workaround--if any--for obtaining the more typical behavior as illustrated by
foo?