Newbie : innerproduct function from Numarray

Ohkyu Yoon okyoon at stanford.edu
Mon Jan 26 16:29:25 EST 2004


I have two vectors that have about 2000 elements.
I need to calculate the innerproducts of those vectors 2000 times where
one of them cycles left(ie 1234, then 2341, then 3412, etc)
Basically, I want to calculate A*x, where A is a left-circulant cyclic
matrix,
and x is a vector.

I tried it two ways.
vector1 & vector2 are lists.

1)
from Numarray import innerproduct
output = []
temp = vector1 + vector1    # temp is twice the length of vector1
for i in range(2000):
     output.append(innerproduct(temp[i:(i+2000)],vector2)
2)
output = []
temp = vector1 + vector1
for i in range(2000):
    sum = 0
    for j in range(2000):
        sum += temp[i+j] * vector2[j]
    output.append(sum)

I thought the first method using Numarray should be faster.
But it looks like the second method is faster.
Am I doing anything wrong?
Do you guys know any faster way to do this?

Thank you.





More information about the Python-list mailing list