[Numpy-discussion] two questions about `choose`
Alan G. Isaac
alan.isaac at gmail.com
Sun Apr 18 08:39:36 EDT 2021
I think you are saying that this current behavior of `choose` should
be considered a bug. I hope not, because as illustrated, it is useful.
How would you propose to efficiently do the same substitutions?
On 4/17/2021 4:27 PM, Kevin Sheppard wrote:
> 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.
> On Sat, Apr 17, 2021, 18:56 Alan G. Isaac <alan.isaac at gmail.com <mailto:alan.isaac at gmail.com>> wrote:
> 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]],
> However, `choose` is happy to have e.g. `choices=(0,seq)` (and I hope it will remain so!).
> 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])
More information about the NumPy-Discussion