Dennis Sweeney <[email protected]> added the comment:
Jacob wrote:
a[[0, *[0, 0], 0]]
which passes the *list* [0, 0, 0, 0] into __getitem__. In numpy, passing lists
into __getitem__ does things like array([1, 10, 100])[[2, 1]] --> array([100,
10]).
But I think Peter is requesting that the following work:
a[0, *[0, 0], 0]
(this is currently a SyntaxError)
and the proposal is that it would pass the *tuple* (0, 0, 0, 0) into
__getitem__, indexing into each dimension of the array.
A workaround is to use a[(0, *[0, 0], 0)] -- just one extra pair of parentheses.
This is a duplicate of https://bugs.python.org/issue43812 , where it was
pointed out that this is currently being proposed as part of
https://www.python.org/dev/peps/pep-0646/#implications , which it appears is in
the queue of things for the steering council to rule on. I'll close this as a
duplicate for now, but feel free to re-open if you feel something is missing
from that PEP.
----------
nosy: +Dennis Sweeney
resolution: -> duplicate
stage: -> resolved
status: open -> closed
superseder: -> Tuple unpacking in getitem
title: Use starred expressions in list indices -> Use starred expressions in
subscripts
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue45586>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com