[Numpy-discussion] Type checking inconsistency
Sun Oct 16 11:39:13 CDT 2011
I noticed a type-checking inconsistency between assignments using slicing
and fancy-indexing. The first will happily cast on assignment (regardless of
type), while the second will throw a type error if there's reason to believe
the casting will be unsafe. I'm not sure which would be the "correct"
behavior, but the inconsistency is surprising.
>>> import numpy as np
>>> a = np.arange(10)
>>> b = np.ones(10, dtype=np.uint8)
# this runs without error
>>> b[:5] = a[:5]
>>> mask = a < 5
>>> b[mask] = b[mask]
TypeError: array cannot be safely cast to required type
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion