[Numpy-discussion] How to remove any row or column of a numpy matrix whose sum is 3?
bob tnur
bobtnur78 at gmail.com
Mon Jun 4 12:39:42 EDT 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.python.org/pipermail/numpy-discussion/attachments/20120604/b9d3d4ff/attachment.html>
More information about the NumPy-Discussion
mailing list