[SciPy-user] howto dot(a, b.T), some a or b coords are zeros
Wed Jan 2 14:47:36 CST 2008
On Jan 2, 2008 1:28 PM, dmitrey <firstname.lastname@example.org> wrote:
> hi all,
> I have 2 vectors a and b of shape (n, 1) (n can be 1...10^3, 10^4, may
> be more); some coords of a or b usually are zeros (or both a and b, but
> b is more often); getting matrix c = dot(a, b.T) is required (c.shape =
> What's the best way to speedup calculations (w/o using scipy, only numpy)?
> (I intend to use the feature to provide a minor enhancement for NLP/NSP
> ralg solver).
How much more expensive is dot(a,b.T) than zeros((n,n))? Is outer()
any faster? What proportion of a and b are zero?
You could remove all zeros from a and b, compute that outer product,
and then paste the results back into an n by n matrix. I doubt this
would be any faster though since the outerproduct doesn't do many
I know you don't want to use scipy, but time the following:
from scipy.sparse import *
asp = csr_matrix(a)
bsp = csr_matrix(b.T)
c = asp * bsp # time this
Nathan Bell email@example.com
More information about the SciPy-user