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

Charles R Harris charlesr.harris at gmail.com
Fri Feb 8 21:44:20 EST 2013


On Fri, Feb 8, 2013 at 5:34 PM, Jaime Fernández del Río <
jaime.frio at gmail.com> wrote:

> On Fri, Feb 8, 2013 at 3:54 PM, Daπid <davidmenhur at gmail.com> wrote:
>
>> TypeError: Cannot cast array data from dtype('uint16') to
>>  dtype('uint8') according to the rule 'safe'.
>>
>
> That really makes it sound like the check is being done the other way
> around!
>
> But I'd be surprised if something so obvious hadn't been seen and reported
> earlier, especially since I have tried it on a Linux box with older
> versions, and things were the same in 1.2.1. So that means this would be a
> 5 year old bug.
>
> >>> np.__version__
> '1.2.1'
> >>> lut = np.random.randint(256, size=(65536,)).astype('uint8')
> >>> arr = np.random.randint(65536, size=(1000, 1000)).astype('uint16')
> >>> np.take(lut, arr)
> array([[ 56, 131, 248, ..., 233,  34, 191],
>        [229, 217, 233, ..., 183,   8,  86],
>        [249, 238,  79, ...,  38,  17,  72],
>        ...,
>        [ 19,  95, 199, ..., 236, 148,  39],
>        [178, 129, 208, ...,  76,  46, 125],
>        [ 66, 196,  71, ..., 227, 252,  94]], dtype=uint8)
> >>> np.take(lut, arr, out=arr)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/usr/lib/python2.6/dist-packages/numpy/core/fromnumeric.py", line
> 97, in take
>     return take(indices, axis, out, mode)
> TypeError: array cannot be safely cast to required type
>
>
>
My money is on 'five year old bug'. Many basic numpy functions are not well
tested. Writing tests is a tedious job but doesn't require any C foo, just
Python an patience, so if anyone would like to get involved...

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130208/9fe7624b/attachment.html>


More information about the NumPy-Discussion mailing list