Newbie : innerproduct function from Numarray

Ohkyu Yoon okyoon at stanford.edu
Tue Jan 27 04:01:45 EST 2004


Wow! Thank you all.
My program runs super fast now.
The biggest problem was changing lists into arrays.
By starting with arrays, the program runs almost infinitely faster.

Ohkyu


"Ohkyu Yoon" <okyoon at stanford.edu> wrote in message
news:bv40rm$ra$1 at news.Stanford.EDU...
> 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