[Numpy-discussion] dtype inconsistancy?

Robert Kern robert.kern at gmail.com
Wed Nov 29 14:48:27 EST 2006


humufr at yahoo.fr wrote:
> Hi,
> 
> I think that the following command and result are a little bit inconsistant 
> and a source of error. I don't understand why: dtype=float32 for a result 
> when it's invalid in the definition.

float32 is an object in the numpy module, i.e. to access it, you must import it
from there.

  import numpy
  a = numpy.array([1], dtype=numpy.float32)

The representation of an object (i.e. what you see in Out[10]) is not
necessarily directly executable in all possible contexts. In fact, it *can't* be
executable in all possible contexts. Note that you already did an interpretation
of the representation: you used "numpy.array()" instead of just "array()".


In [1]: import numpy

In [2]: a = numpy.array([1], dtype=numpy.float32)

In [3]: a
Out[3]: array([ 1.], dtype=float32)

In [4]: array([ 1.], dtype=float32)
---------------------------------------------------------------------------
<type 'exceptions.NameError'>             Traceback (most recent call last)

/Users/rkern/src/wsgiref/<ipython console> in <module>()

<type 'exceptions.NameError'>: name 'array' is not defined


-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco



More information about the NumPy-Discussion mailing list