[Numpy-discussion] Matching 0-d arrays and NumPy scalars
Fri Feb 22 16:05:42 CST 2008
Travis, after reading all the post on this thread, my comments
Fist of all, I'm definitelly +1 on your suggestion. Below my rationale.
* I believe numpy scalars should provide all possible features needed
to smooth the difference between mutable, indexable 0-d arrays and
inmutable, non-indexable builtin Python numeric types.
* Given that in the context of generic multi-dimensional array
processing a 0-d array are more natural and useful concept that a
Python 'int' and 'float', I really think that numpy scalars shoud
follow as much as possible the behavior of 0-d arrays (of course,
* Numpy scalars already have (thanks for that!) a very, very similar
API to ndarrays. You can as for 'size', 'shape', etc ( BTW, why
scalar.fill(x) does not generate any error????). Why do not add
indexing as well?
* However, I'm not sure about the proposal of supporting len(), I'm -0
on this point. Anyway, if this is added, then 0-d arrays should also
have to support it. And then... len(scalar) or len(0-d-array) is going
to return 0 (zero)?
On 2/21/08, Travis E. Oliphant <firstname.lastname@example.org> wrote:
> In writing some generic code, I've encountered situations where it would
> reduce code complexity to allow NumPy scalars to be "indexed" in the
> same number of limited ways, that 0-d arrays support.
> For example, 0-d arrays can be indexed with
> * Boolean masks
> * Ellipses x[...] and x[..., newaxis]
> * Empty tuple x[()]
> I think that numpy scalars should also be indexable in these particular
> cases as well (read-only of course, i.e. no setting of the value would
> be possible).
> This is an easy change to implement, and I don't think it would cause
> any backward compatibility issues.
> Any opinions from the list?
> Best regards,
> -Travis O.
> Numpy-discussion mailing list
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
More information about the Numpy-discussion