[Numpy-discussion] How to remove any row or column of a numpy matrix whose sum is 3?
bob tnur
bobtnur78@gmail....
Mon Jun 4 11:21:02 CDT 2012
Hello every body. I am new to python.
How to remove any row or column of a numpy matrix whose sum is 3.
To obtain and save new matrix P with (sum(anyrow)!=3 and sum(anycolumn)!=3
elements.
I tried like this:
P = M[np.logical_not( (M[n,:].sum()==3) & (M[:,n].sum()==3))]
or
P = M[np.logical_not( (np.sum(M[n,:])==3) & (np.sum(M[:,n])==3))]
M is the nxn numpy matrix.
But I got indexerror. So can anyone correct this or any other elegant way
of doing this?
Thanks for your help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20120604/a8816e24/attachment.html
More information about the NumPy-Discussion
mailing list