views:

72

answers:

1

Hi everyone,

I have a question about numpy.matrix class. How can I perform such basic manipulations with matrices as adding, deleting and replacing rows and columns?

p.s. I apologize for the lame question..

+3  A: 

Perfectly fine question! Try examining this code:

import scipy
X = scipy.rand(3,3)
Y = scipy.rand(3,3)
print X+Y
print scipy.delete(X, 1, 0)
print scipy.delete(X, 1, 1)
X[1,:] = [1,2,3]
print X

For more, see the numpy/scipy docs here: NumPy/SciPy docs

If you are fluent in Matlab, this page is useful: NumPy for Matlab Users

Steve
Note that `X[1] = …` is faster than `X[1,:]` (because no interpretation of the slice is necessary, I would guess).
EOL
Ah, good to know.
Steve