[Numpy-discussion] PEP updated
tkorvola at welho.com
Sun Feb 20 05:40:23 CST 2005
Travis Oliphant <oliphant at ee.byu.edu> writes:
> I've updated the PEP to conform to what I think is the best hybrid
> solution propsed and that is to implement a tree of PythonTypes in C
> whose leaves are (to the Python user) new rank-0 arrays.
For the purpose of differentiating between basic and advanced
indexing, are rank 0 arrays considered scalars or arrays? Does their
presence among indices trigger advanced indexing?
For sequence behaviour len, indexing and iteration should work
consistently, i.e., "a[i] for i in xrange(len(a))" and "x for x in a"
should identically generate the contents of a. Currently indexing and
iteration occur along the first dimension, which for rank 0 arrays
does not exist. I understand that there is no burning desire to
completely switch to Matlab-style one-dimensional indexing. The
alternatives are then giving rank 0 arrays exceptional semantics
inconsistent with other arrays or raising an exception if len or
iteration is applied to a rank 0 array. Without exceptional semantics
the only index expression that makes sense is a[()]. I would favor
consistency here and raise an exception but there is one matter that
raises some doubt: do programs expect that if __len__ and __iter__
exist they will not fail?
Converting scalars back to arrays: they should be rank 0. Rank 1
would be Matlabish nonsense, except that Matlab is even more
nonsensical and uses rank 2. But when is such conversion needed? If
it is only for operations with other arrays then broadcasting is
likely to occur immediately.
Timo Korvola <URL:http://www.iki.fi/tkorvola>
More information about the Numpy-discussion