This undocumented method has puzzling behaviour. [Dbg]>>> a array([[0, 1, 2], [3, 4, 5], [6, 7, 8]]) [Dbg]>>> b= a[1:1] [Dbg]>>> b array([]) [Dbg]>>> b.shape (0, 3) [Dbg]>>> b.rank 2 I had expected a rank of zero and an indeterminate shape. Colin W.
"Colin J. Williams" <cjw@sympatico.ca> writes:
I had expected a rank of zero and an indeterminate shape.
Rank zero would imply shape () and that the result is a scalar. Empty arrays have positive rank but one or more of the dimensions are zero. It seems that there is a bug in repr as it does not distinguish between empty arrays of different shapes. The current behaviour is consistent in the sense that indexing by a slice does not change rank, not even if the slice has length zero or one (a slice of length one is thus different from an integer). Only the indexed dimension changes. -- Timo Korvola <URL:http://www.iki.fi/tkorvola>
Timo Korvola wrote:
"Colin J. Williams" <cjw@sympatico.ca> writes:
I had expected a rank of zero and an indeterminate shape.
Rank zero would imply shape () and that the result is a scalar. Empty arrays have positive rank but one or more of the dimensions are zero. It seems that there is a bug in repr as it does not distinguish between empty arrays of different shapes.
Perhaps the problem is in str:
b= a[:,1:1] b.shape (3, 0) str(b) '[]' repr(b) 'array([])'
The current behaviour is consistent in the sense that indexing by a slice does not change rank, not even if the slice has length zero or one (a slice of length one is thus different from an integer). Only the indexed dimension changes.
Yes, you are right. The new docs are a great step forward but it would be good to include the take method. Colin W.
participants (2)
-
Colin J. Williams -
Timo Korvola