Matrixspalten umstellen
Verfasst: Montag 9. Mai 2016, 19:01
Wenn ich (auf elegante Art) die Spalten einer Matrix umstellen möchte, kann ich das so wie folgt NICHT machen:
Das beste was mir bisher dazu einfällt ist
aber das ist wohl nicht zu empfehlen, oder?
Code: Alles auswählen
import scipy as sc
mat = sc.matrix([[1,2,3,], [4,5,6], [7,8,9]])
#
(mat[:,0], mat[:,1]) = (mat[:,1], mat[:,0]) #FALSCH
print(mat)
Code: Alles auswählen
import scipy as sc
mat = sc.matrix([[1,2,3,], [4,5,6], [7,8,9]])
#
lst = [zeile for zeile in sc.array(mat.T)]
(lst[0], lst[1]) = (lst[1], lst[0])
mat = sc.matrix(lst).T
print(mat)