[Numpy-discussion] Square All Elements Of A Matrix
andrea_gavana at tin.it
andrea_gavana at tin.it
Wed May 11 13:04:29 EDT 2005
Hello NG,
in one script, I generated a matrix "dx" which has a (200000, 10) shape.
Well, everything is working fine (matrix multiplication, sum, exponentiation
etc...), but I'm having problems in squaring all elements of this matrix.
Suppose I have:
import Numeric
import random
dx = Numeric.ones((200000,10), Numeric.Float0, savespace=1)
dx[:,:] = random.random()
td1 = dx*2.0 ---> This takes about 0.2 seconds
td2 = dx**2.0 ---> This takes about 6 seconds
Why this difference? And why it is so slow the exponentiation? I have tried
the same operation in Matlab and it was almost instantaneous. I don't want
to stick with Matlab, noting the great job the Numeric developers have done.
Is there something that I am missing?
Sorry if it is a basic question.
Andrea.
More information about the NumPy-Discussion
mailing list