[Numpy-discussion] correct way to specify type in array definition

Francesc Altet faltet at carabos.com
Thu Mar 15 06:23:36 EDT 2007


El dj 15 de 03 del 2007 a les 06:01 -0400, en/na Brian Blais va
escriure:
> Hello,
> 
> Can someone tell me what the preferred way to specify the type of an array?  I want
> it to be a float array, no matter what is given (say, integers).  I can do:
> 
> a=numpy.array([1,2,3],numpy.dtype('float'))
> 
> or
> 
> a=numpy.array([1,2,3],type(1.0))
> 
> or perhaps many others.  Is there a way that is recommended?

Well, this depends on your preferences, I guess, but I like to be
explicit, so I normally use:

a=numpy.array([1,2,3], numpy.float64)

but, if you are a bit lazy to type, the next is just fine as well:

a=numpy.array([1,2,3], 'f8')

Cheers,

-- 
Francesc Altet    |  Be careful about using the following code --
Carabos Coop. V.  |  I've only proven that it works, 
www.carabos.com   |  I haven't tested it. -- Donald Knuth




More information about the NumPy-Discussion mailing list