[Numpy-discussion] Matching 0-d arrays and NumPy scalars
Fri Feb 22 01:42:40 CST 2008
On 21.02.2008, at 18:40, Alan G Isaac wrote:
>>>> x = N.array([1,2],dtype='float')
>>>> x0 = x
> <type 'numpy.float64'>
> So a "float64 value" is whatever a numpy.float64 is,
> and that is part of what is under discussion.
numpy.float64 is a very recent invention. During the first decade of
numerical arrays in Python (Numeric), typ(x0) was the standard Python
float type. And even today, what you put into an array (via the array
constructor or by assignment) is Python scalar objects, mostly int,
float, and complex.
The reason for defining special types for the scalar elements of
arrays was efficiency considerations. Python has only a single float
type, there is no distinction between single and double precision.
Extracting an array element would thus always yield a double
precision float, and adding it to a single-precision array would
yield a double precision result, meaning that it was extremely
difficult to maintain single-precision storage across array
arithmetic. For huge arrays, that was a serious problem.
However, the intention was always to have numpy's scalar objects
behave as similarly as possible to Python scalars. Ideally,
application code should not see a difference at all. This was largely
successful, with the notable exception of the coercion problem that I
mentioned a few mails ago.
More information about the Numpy-discussion