Scipy sparse… arrays?

前端 未结 3 724
感动是毒
感动是毒 2020-12-13 03:44

So, I\'m doing some Kmeans classification using numpy arrays that are quite sparse-- lots and lots of zeroes. I figured that I\'d use scipy\'s \'sparse\' package to reduce

3条回答
  •  醉酒成梦
    2020-12-13 04:12

    I'm not sure that it is really much better or faster, but you could do this to avoid using the transpose:

    Asp.multiply(Bsp).sum()
    

    This just takes the element-by-element product of the two matrices and sums the products. You could make a subclass of whatever matrix format you are using that has the above statement as the dot product.

    However, it is probably just easier to tranpose them:

    Asp*Bsp.T
    

    That doesn't seem like so much to do, but you could also make a subclass and modify the mul() method.

提交回复
热议问题