Can anyone explain this behavior?
print np.array(None)
> None
print np.array(None) is None
> False
You have an object that has None as the str() value, so that's what is printed:
>>> import numpy as np
>>> np.array(None)
array(None, dtype=object)
>>> str(np.array(None))
'None'
That's a string value with the letters N, o, n and e. That's not the same thing as the None singleton object, it just looks the same when printed.
You actually have an array object whose string representation is None, and not the None object as you suppose:
>>> np.array(None)
array(None, dtype=object)
>>> str(_)
'None'
Which is why the print statements shows None.
However, what you're actually doing is:
np.array(None) is None # False
printoutput is ambiguous. The fact that two things print the same doesn't mean they're the same object, or even that they're equal or that they have the same type. After all,print 'None'andprint Noneprint the same thing, but hopefully you're not surprised that'None' != None.np.array(1)andnp.array(2)has the same behavior