Hi, I see there is a lot of ongoing discussion on casting rules, but I couldn't find any reference to the following issue I am facing. I am trying to 'take' from an array of uint8's, using an array of uint16's as indices. Even though the return dtype would be uint8, I want to direct the output back into the array of uint16's:
>>> lut = np.random.randint(256, size=(65536,)).astype('uint8') >>> arr = np.random.randint(65536, size=(1000, 1000)).astype('uint16') >>> np.take(lut, arr, out=arr) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python27\lib\site-packages\numpy\core\fromnumeric.py", line 103, in take return take(indices, axis, out, mode) TypeError: array cannot be safely cast to required type This is puzzling, since the only casting that should be happening is from uint8's to uint16's, which is as safe as it gets: >>> np.can_cast('uint8', 'uint16') True To make things even weirder, I can get the above code to work if the type of lut is uint16, uint32, uint64, int32 or int 64, but not if it is uint8, int8 or int16. Without looking at the source, it almost looks as if the type checking in numpy.take was reversed... Am I missing something, or is this broken? My numpy's version is: >>> np.__version__ '1.6.2' which is the one packaged in Python xy 2.7.3.1, running on a 64 bit Windows 7 system. Thanks, Jaime P.S. I have posted the same question in StackExchange: http://stackoverflow.com/questions/14782135/type-casting-error-with-numpy-take -- (\__/) ( O.o) ( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus planes de dominación mundial.
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion