Sympy: rref() should return a Matrix

Created on 11 Sep 2016  路  5Comments  路  Source: sympy/sympy

Currently calling .rref() on a matrix produces a tuple with a matrix and a list of pivots. I think this is unexpected for new users and the default should be that rref() returns the row-reduced matrix only. An include_pivots flag could be added to get the current behavior where a tuple is returned.

Needs Decision matrices

Most helpful comment

How about simply adding some documentation improvements that show clearly what is returned? Like how you would only grab the matrix, i.e. reduced, _ = M.rref().

All 5 comments

How about simply adding some documentation improvements that show clearly what is returned? Like how you would only grab the matrix, i.e. reduced, _ = M.rref().

I think this is more than a documentation issue. Octave, matlab, sage, mathematica, and maple all allow you to write code like

X = Y.rref()

and then continue to manipulate the matrix X. The current method would be better named something like rref_and_pivots(), but the _reduced row echelon form_ of a matrix should be a matrix. Mathematically one expects rref: Matrix -> Matrix. In sympy rref: Matrix -> (Matrix, list), which is a bit strange.

I wasn't trying to imply it was a documentation issue, just raising an alternative to deprecating the functionality. Someone wrote the code with this API. It happens to be different than the API of other software, but if it is well documented then I personally think it's fine. But if it differs from the rest of our API, as you suggest, then deprecation may be the right thing to do.

What about adding passing a parameter like pivot=True?

I like the idea of adding a parameter. If a parameter is added then the current default of giving matrix,pivots can be deprecated and eventually changed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GarkGarcia picture GarkGarcia  路  4Comments

JanVanDieBos picture JanVanDieBos  路  3Comments

asmeurer picture asmeurer  路  3Comments

astrojuanlu picture astrojuanlu  路  6Comments

nschloe picture nschloe  路  3Comments