[Numpy-discussion] Scalar array - a trap for the unwary

Sasha ndarray at mac.com
Sat Jan 21 16:58:00 CST 2006


On 1/21/06, Colin J. Williams <cjw at sympatico.ca> wrote:
> ...
> I much prefer the numarray treatment, particularly in a matrix context.
> I suggest that, if it looks like an integer, b[1] should return a Python
> scalar.

In NumPy b[1] IS an integer:
>>> from numpy import *
>>> a = array([1,2,3])
>>> b = a[1]
>>> isinstance(b, int)
True

It IS NOT rank-0 ndarray:
>>> isinstance(b, ndarray)
False

Surely, the whole truth is that numpy scalars are instances of classes
derived from Python scalars.  What is the problem that numpy is
causing you? If b was a python scalar, b.dtype would just raise an
AttributeError.

-- sasha




More information about the Numpy-discussion mailing list