On Fri, Apr 19, 2013 at 9:40 PM, Sebastian Berg <sebast...@sipsolutions.net> wrote:
> Fun fact, array[()] will convert a 0-d array to a scalar, but do nothing > (or currently create a view) for other arrays. Which is actually a good > question. Should array[()] force a view or not? Another fun fact: scalar[()] gives you a rank-0 array. :-) I think the array[()] behavior follows logically as a limiting form of multidimensional indexing. Given rank-3 array, array[(i, j, k)] gives a scalar array[(i, j)] gives a rank-1 view of the last axis array[(i,)] gives a rank-2 view of the last 2 axes array[()] gives a rank-3 view of the last 3 axes (i.e. all of them) The rank-N-general rules look like so: For a rank-N array, an N-tuple gives a scalar. Subsequent (N-M)-tuples gives appropriate rank-M views picked out by the tuple. I can't explain the scalar[()] behavior, though. :-) -- Robert Kern _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion