[Numpy-discussion] two questions about `choose`
bas van beek
bas.vanbeek at hotmail.com
Mon Apr 19 12:22:33 EDT 2021
After a taking a closer look at the `np.choose` docs I think we should change `choices: npt.ArrayLike` into `choices: Sequence[npt.ArrayLike]`.
This would resolve the issue, but it’d also mean that directly passing an array will be prohibited (as far as type checkers are concerned).
The docs do mention that the outermost container should be a list or tuple anyway, so I’m not convinced that this new typing restriction would be a huge loss.
From: NumPy-Discussion <numpy-discussion-bounces+bas.vanbeek=hotmail.com at python.org> On Behalf Of Kevin Sheppard
Sent: 18 April 2021 20:08
To: Discussion of Numerical Python <numpy-discussion at python.org>
Subject: Re: [Numpy-discussion] two questions about `choose`
Oh. I answered thinking about choice and not choose. Please ignore both parts.
On Sun, Apr 18, 2021, 17:56 Robert Kern <robert.kern at gmail.com<mailto:robert.kern at gmail.com>> wrote:
On Sat, Apr 17, 2021 at 4:28 PM Kevin Sheppard <kevin.k.sheppard at gmail.com<mailto: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.
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)))`
NumPy-Discussion mailing list
NumPy-Discussion at python.org<mailto:NumPy-Discussion at python.org>
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion