[Numpy-discussion] Bug or feature ?

konrad.hinsen at laposte.net konrad.hinsen at laposte.net
Mon Jan 24 07:30:20 CST 2005


On Jan 24, 2005, at 16:19, Jean-Luc Menut wrote:

> When I write :
>>> a = array([[1, 2],[3, 4]])
>>> >>> a[0,0]=1.1
>
> I cannot expect to have a = array([[1.1, 2],[3, 4]]) ?

No. All elements in an array are of the same type.

> How can I solve this problem ? is it possible to force an array to be 
> an
> array of float ?

Yes, at creation time:

from Numeric import array, Float
a = array([[1, 2], [3, 4]], Float)

wil create a float array. All the integers are then converted to floats.

Konrad.
--
---------------------------------------------------------------------
Konrad Hinsen
Laboratoire Léon Brillouin, CEA Saclay,
91191 Gif-sur-Yvette Cedex, France
Tel.: +33-1 69 08 79 25
Fax: +33-1 69 08 82 61
E-Mail: hinsen at llb.saclay.cea.fr
---------------------------------------------------------------------





More information about the Numpy-discussion mailing list