[Numpy-discussion] Type casting problems with numpy.take

Daπid davidmenhur@gmail....
Fri Feb 8 17:54:06 CST 2013


On 9 February 2013 00:12, Jaime Fernández del Río <jaime.frio@gmail.com> wrote:
> TypeError: array cannot be safely cast to required type

With version 1.7.rc1

TypeError: Cannot cast array data from dtype('uint16') to
dtype('uint8') according to the rule 'safe'.


I have also tried with bigger values of lut, being it uint32, so, when
they are casted to uint16 they are modified, and it will do it without
complaining:


>>> lut = np.random.randint(256000, size=(65536,)).astype('uint16')
>>> arr = np.random.randint(65536, size=(1000, 1000)).astype('uint16')
>>> np.take(lut, arr, out=arr)
>>> arr.dtype
dtype('uint16')


More information about the NumPy-Discussion mailing list