-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Index multi-dimensional arrays with a tuple? #6856
Comments
This proposal would seem to conflict with the plans to use tuples as fixed-size immutable arrays (#5857), which would suggest that |
It might be possible in the future to wrap a tuple in an immutable type with no overhead. |
Still, you can already to A[(1,2)...] to get the same effect, and i suspect |
My opinion is that, regardless of what is done, it has to be clear what such operation means. |
This can now be done by wrapping the tuple in a |
It definitely is. One still might wonder about defining all the operations we allow on Semi-related: recent case in which we discuss indexing with tuples-of- |
Would it make sense to allow tuples to index multi-dimensional arrays? For example, if
A
is a 2D matrix, thenA[(2, 1)]
would do the same thing asA[2,1]
.The rationale for this is that sometimes it is more convenient to work with, and pass around, a single variable which contains all the indexing information, instead of d separate coordinates. For example, if
loc
is an(Int, Int)
tuple representing the current location on a grid, it would be nice to be able to write:instead of
sum += A[loc...]
.One potential cause for confusion is that this would mean
A[[1:2]]
andA[(1, 2)]
would do different things. However, seeing asA[(1, 2)]
is currently undefined, it seems like it should be ok.The text was updated successfully, but these errors were encountered: