[SciPy-user] manipulate arrays/matrices
David Douard
david.douard at logilab.fr
Wed Jun 7 05:22:22 EDT 2006
On Wed, Jun 07, 2006 at 09:42:19AM +0200, Nils Wagner wrote:
> Hi all,
>
> Is there a better way to interchange two rows/columns of an array ?
>
Hi, using numpy:
from numpy import *
A = diag(arange(1,n+1))+diag(ones(n-2),2)+diag(ones(n-2),-2)
# swap rows 1 and 3
A[array([1,3])] = A[array([3,1])]
#swap columns 1 and 3
A[:,array([1,3])] = A[:,array([3,1])]
David
--
David Douard LOGILAB, Paris (France)
Formations Python, Zope, Plone, Debian : http://www.logilab.fr/formations
Développement logiciel sur mesure : http://www.logilab.fr/services
Informatique scientifique : http://www.logilab.fr/science
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20060607/812f0c47/attachment.sig>
More information about the SciPy-User
mailing list