Reduced Row Echelon Form

mit matplotlib, NumPy, pandas, SciPy, SymPy und weiteren mathematischen Programmbibliotheken.
Antworten
Basilius Sapientia
User
Beiträge: 46
Registriert: Freitag 5. September 2014, 22:34

Gibt es ein eingebautes Stück Kot, dass dies für mich übernehmen könnte? Etwas wie

Code: Alles auswählen

np.echelon(A)
oder sonst etwas? Ich könnte natürlich auch dies hier machen

Code: Alles auswählen

def ToReducedRowEchelonForm( M):
    if not M: return
    lead = 0
    rowCount = len(M)
    columnCount = len(M[0])
    for r in range(rowCount):
        if lead >= columnCount:
            return
        i = r
        while M[i][lead] == 0:
            i += 1
            if i == rowCount:
                i = r
                lead += 1
                if columnCount == lead:
                    return
        M[i],M[r] = M[r],M[i]
        lv = M[r][lead]
        M[r] = [ mrx / float(lv) for mrx in M[r]]
        for i in range(rowCount):
            if i != r:
                lv = M[i][lead]
                M[i] = [ iv - lv*rv for rv,iv in zip(M[r],M[i])]
        lead += 1
 
 
mtx = [
   [ 1, 2, -1, -4],
   [ 2, 3, -1, -11],
   [-2, 0, -3, 22],]
 
ToReducedRowEchelonForm( mtx )
 
for rw in mtx:
  print ', '.join( (str(rv) for rv in rw) )
Dennoch denke ich, es müsste eine einfachere Methode existieren? Schließlich haben wir ja Scipy :D

Liebe Grüße!

Sorry for my bad German!
Benutzeravatar
MagBen
User
Beiträge: 799
Registriert: Freitag 6. Juni 2014, 05:56
Wohnort: Bremen
Kontaktdaten:

Basilius Sapientia hat geschrieben:Gibt es ein eingebautes Stück Kot
"Kot" means dung (or worse).

Nicht in Numpy oder Scipy wg
http://mail.scipy.org/pipermail/numpy-d ... 38705.html

aber in Sympy
http://docs.sympy.org/0.7.5/tutorial/matrices.html#rref
a fool with a tool is still a fool, www.magben.de, YouTube
Basilius Sapientia
User
Beiträge: 46
Registriert: Freitag 5. September 2014, 22:34

Vielen Dank!
Antworten