[Numpy-discussion] dot-product of selected columns or rows

Alexander Schmolck a.schmolck at gmx.net
Mon May 23 17:13:28 EDT 2005


Suppose I have some iterative algorithm that selects and deselects 'features'
represented by a list of indices `active` that correspond to rows (or
equivalently columns) in some matrices `M`, `N`, ...

What would be the most efficient way to carry out the equivalent of:

  A = dot(take(M, active), take(C, active),axis=1)

assuming that M and C remain constant throughtout the computation and that A
could be modified in-place for the relevant indices in `active`.

Also am I right to assume that generally the best approach to cheaply create a
matrix with a different diagonal from a square and contiguous n*n matrix `S`
(that is no longer needed) would be the following in-place operation?

  S.flat[::n+1] += vec


In case it matters: I'm using Numeric and scipy, but not numarray.

'as





More information about the NumPy-Discussion mailing list