[Numpy-discussion] Wanted: Numeric/NumPy compatible array creation expression

Robert kxroberto at googlemail.com
Thu Nov 23 09:29:00 CST 2006


konrad.hinsen at laposte.net wrote:
> I am looking for a way to create an array of the same type as another  
> given array (but of different shape) that works both with Numeric and  
> NumPy without being unreasonably slow. In other words, I am looking  
> for a a replacement for the expression
> 
> 	array2 = Numeric.zeros(shape, array1.typecode())
> 
> that will *also* (not *only*) work under NumPy (where typecode()  
> became dtype.char). An obvious idea is reshaping array1 and  
> multiplying by 0., but that can become quite costly.

timeit if *0 is really costly ... you'll not get it really cheaper I think.
As you write just "same type": .copy().reshape() or so maybe ok too, in case you'll fill in stuff into this array anyway

> Any ideas?
> 
> Konrad.
> --
> ---------------------------------------------------------------------
> Konrad Hinsen
> Centre de Biophysique Moléculaire, CNRS Orléans
> Synchrotron Soleil - Division Expériences
> Saint Aubin - BP 48
> 91192 Gif sur Yvette Cedex, France
> Tel. +33-1 69 35 97 15
> E-Mail: hinsen at cnrs-orleans.fr
> ---------------------------------------------------------------------



More information about the Numpy-discussion mailing list