Newbie : innerproduct function from Numarray
David M. Cooke
cookedm+news at physics.mcmaster.ca
Mon Jan 26 17:38:22 EST 2004
More information about the Python-list mailing list
Mon Jan 26 17:38:22 EST 2004
- Previous message (by thread): Newbie : innerproduct function from Numarray
- Next message (by thread): Newbie : innerproduct function from Numarray
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
At some point, "Ohkyu Yoon" <okyoon at stanford.edu> wrote: > 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. ^^^^^^ This is your problem: everytime you pass these to innerproduct, it turns them into arrays (which, with the current version of numarray, is a relatively expensive operation). Try something like import numarray as na output = [] vector1 = na.array(vector1) vector2 = na.array(vector2) temp = na.concatenate((vector1,vector1)) # temp is twice the length of vector1 for i in range(2000): output.append(na.innerproduct(temp[i:(i+2000)],vector2) This uses arrays always. You might be better off explicity constructing your left-circulant cyclic matrix A, and doing the full matrix multiply -- for this size of matrix, the multiply is going to be fast (because it's going to be done by code written in C, and, depending on how you set it up, using an optimized BLAS routine). -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca
- Previous message (by thread): Newbie : innerproduct function from Numarray
- Next message (by thread): Newbie : innerproduct function from Numarray
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list