Steven G. Johnson
unread,Dec 27, 2012, 2:51:33 PM12/27/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to juli...@googlegroups.com
Right now, tuples and arrays can be used in somewhat similar ways, but
with some seemingly random inconsistencies.
Consider `a = [1,2,3,4]` and `t = (1,2,3,4)`, for example. `a[1]` and
`t[1]` both work to give a single element, and `a[1:3]` and `t[1:3]`
both work to get subarray/tuple. However, arrays accept arrays of
indices while tuples do not, and neither accept tuples of indices:
`a[a]` works, but neither `t[a]` nor `a[t]` nor `t[t]` do.
`sum` and `prod` work for both arrays and tuples, but `mean` only works
for arrays.
`sum(A,dims)` works if `dims` is a tuple, but not if `dims` is an array.
Is there a general principle underlying when tuples are used and when
arrays are used?
One possible guiding principle might be that in any context involving an
array index, e.g. `[...]` or `Dimspec`, if it makes sense to allow
multiple indices then either an array or a tuple or a range should be
allowed.