[Numpy-discussion] Selecting columns of a matrix (original) (raw)

Keith Goodman kwgoodman at gmail.com
Wed Jun 21 10:56:42 EDT 2006


Alan G Isaac wrote:

M.transpose()[V>0] If you want the columns as columns, you can transpose again.

I can't get that to work when M is a n by m matrix:

M = asmatrix(rand(3,4))

M

matrix([[ 0.78970407, 0.78681448, 0.79167808, 0.57857822], [ 0.44567836, 0.23985597, 0.49392248, 0.0282004 ], [ 0.7044725 , 0.4090776 , 0.12035218, 0.71365101]])

V = asmatrix(rand(4,1))

V

matrix([[ 0.61638738], [ 0.76928157], [ 0.3882811 ], [ 0.68979661]])

M.transpose()[V > 0.5] matrix([[ 0.78970407, 0.78681448, 0.57857822]])

The answer should be a 3 by 3 matrix.



More information about the NumPy-Discussion mailing list