[Numpy-discussion] two questions about `choose`

Robert Kern robert.kern at gmail.com
Sun Apr 18 12:54:54 EDT 2021


On Sat, Apr 17, 2021 at 4:28 PM Kevin Sheppard <kevin.k.sheppard at gmail.com>
wrote:

> 1. I suppose it only uses the (Native int or int64) dtype since each one
> would need a code path to run quickly.
>
> 2. I would describe this a a bug. I think sequences are converted to
> arrays and in this case the conversion is not returning a 2 element object
> array but expanding and then concatenation.
>

No, it's broadcasting the two to a common shape, as documented.
https://numpy.org/doc/stable/reference/generated/numpy.choose.html


> E.g.,
>> a = a = (0,1,1,0,0,0,1,1)  #binary array
>> np.choose(a, (0,range(8))     #array([0, 1, 2, 0, 0, 0, 6, 7])
>>
>
This is equivalent to `np.choose(a, (np.zeros(8, dtype=int), range(8)))`

-- 
Robert Kern
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/numpy-discussion/attachments/20210418/da0ad9b3/attachment.html>


More information about the NumPy-Discussion mailing list