[Numpy-discussion] two questions about `choose`

Kevin Sheppard kevin.k.sheppard at gmail.com
Sat Apr 17 16:27:13 EDT 2021


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.

Kevin


On Sat, Apr 17, 2021, 18:56 Alan G. Isaac <alan.isaac at gmail.com> wrote:

> 1. Is there a technical reason for `choose` not accept a `dtype` argument?
>
> 2. Separately, mypy is unhappy with my 2nd argument to `choose`:
> Argument 2 to "choose" has incompatible type "Tuple[int, Sequence[float]]";
> expected "Union[Union[int, float, complex, str, bytes, generic],
> Sequence[Union[int, float, complex, str, bytes, generic]],
> Sequence[Sequence[Any]],_SupportsArray]"
> However, `choose` is happy to have e.g. `choices=(0,seq)` (and I hope it
> will remain so!).
>
> E.g.,
> a = a = (0,1,1,0,0,0,1,1)  #binary array
> np.choose((0,range(8))     #array([0, 1, 2, 0, 0, 0, 6, 7])
>
> Thanks, Alan Isaac
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/numpy-discussion/attachments/20210417/adac7ab2/attachment.html>


More information about the NumPy-Discussion mailing list