On Thu, Mar 15, 2007 at 11:23:36AM +0100, Francesc Altet wrote: > 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') >
I just do a = numpy.array([1,2,3], dtype=float) The Python types int, float, and bool translate to numpy.int_, numpy.double, and numpy.bool (i.e., the C equivalents of the Pythonn types; note that int_ is a C long). -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke http://arbutus.physics.mcmaster.ca/dmc/ |[EMAIL PROTECTED] _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion