0

Continuing my line of uninformed questioning on SciPy sparse matrix operations, I've run into a challenge that I know there must be a work around for.

V1 = sparse.csc_matrix([1 for i in xrange(100000)]).T
V2 = 1.0 / 100000 * V1
A = V2 * V1.T

V1 and V2 will be a column vectors. V1 is transposed. The multiplcation blows the product matrix up into a fully dense matrix. e.g. 10000 x 10000

I'm not a mathmatician, I just need to understand if there's a way to deal with this. Is there a better way to do this? Maybe construct a complete sparse matrix with all 1s instead of 0s as the sparse value before operation? Thanks.

Community
  • 1
  • 1
dubmojo
  • 6,660
  • 8
  • 41
  • 68
  • 2
    It's not clear what you're asking. If you compute `A` that way, then `A` should be a sparse CSR matrix, and it'll have only as many elements as you need. – DSM Mar 27 '15 at 21:16
  • @DSM: In the particular example shown, `V1` is all 1s, so `A` has no zero elements. – Warren Weckesser Mar 27 '15 at 21:28
  • *"I just need to understand if there's a way to deal with this."* This question is about the outer product of two vectors, which naturally creates a fully populated array if the vectors are mostly nonzero. To answer the question "is there a better way?", I think we need to know *why* you are computing this outer product. What are you going to do with `A`? – Warren Weckesser Mar 27 '15 at 21:31
  • @Warren: as I said, as many elements as you need.. which in this case is all of them, but needn't be in the general case.. Hopefully the OP doesn't actually need the materialized matrix but some function of it instead. – DSM Mar 27 '15 at 21:34
  • Are you seeking a better way to get this same result? Or do you want a different result? – hpaulj Mar 27 '15 at 22:00
  • This is similar to the 'ones' operator in the example at the top of https://github.com/scipy/scipy/blob/master/scipy/sparse/linalg/interface.py. – identity-m Mar 30 '15 at 17:53

0 Answers0