[Numpy-discussion] matrix operation.

gerardo.berbeglia gberbeglia@gmail....
Mon Mar 15 10:09:35 CDT 2010


I have another matrix operations which seems a little more complicated.

Let A be an n x n matrix and let S be a subset of {0,...,n-1}. Assume
S is represented by a binary vector s, with a 1 at the index i if i is
in S. (e.g. if S={0,3} then s = [1,0,0,1])

I re-post the question because the example was wrong.

I would like to have an efficient way to compute the function B = f
(A,S) characterized as follows:

- For each column i such that i is in S, then the column i of B is
equal to the column i of A.

- For each column i such that i is NOT in S, then the column i of B is
equal to the ith column of the n x n identity matrix.

Example. n=4.
A = [[2,3,4,5],
      [3,4,5,6]
      [4,5,6,7]
      [5,6,7,8]]

S = {0,2} => s=[1,0,1,0]

f(A,S) = [[2,0,4,0],
            [3,1,5,0],
            [4,0,6,0],
            [5,0,7,1]]

Which is the best way to compute f?

Thanks again. 
-- 
View this message in context: http://old.nabble.com/matrix-operation.-tp27905661p27905661.html
Sent from the Numpy-discussion mailing list archive at Nabble.com.



More information about the NumPy-Discussion mailing list