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

Robert kxroberto at googlemail.com
Thu Nov 23 11:44:10 EST 2006


konrad.hinsen at laposte.net wrote:
> On 23.11.2006, at 16:29, Robert wrote:
> 
>>> 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.
> 
> What I expect to be costly is the reshape (resize in most  
> situations), not the multiplication. I didn't do any timings though...
> 

its simple with:

a=...
import timeit
timeit.Timer("b=a.reshape....",glbls=globals()).timeit(1000)

reshaping is usually very cheap (numpy), as only an new view with other index geometry is created. 
A (unavoidable?) copy is probably the most expensive but just test ... 



Robert




More information about the NumPy-Discussion mailing list