Skip to content

Matrix results with a single column come back as a vector (Inverse[{{2}}], RowReduce[{{1}, {2}}], ...) #2006

Closed

Description

@tombouctou

Matrix results that come back from SymPy with a single column are returned as a vector instead of an n×1 matrix:

In[1]:= Inverse[{{2}}]
Out[1]= {1/2}            (* WMA: {{1/2}} *)

In[2]:= RowReduce[{{1}, {2}}]
Out[2]= {1, 0}           (* WMA: {{1}, {0}} *)

In[3]:= MatrixPower[{{2}}, 3]
Out[3]= {8}              (* WMA: {{8}} *)

In[4]:= MatrixExp[{{0}}]
Out[4]= {1}              (* WMA: {{1}} *)

In[5]:= Transpose[{{1, 2, 3}}]
Out[5]= {1, 2, 3}        (* WMA: {{1}, {2}, {3}} *)

The cause is from_sympy_matrix in mathics/core/convert/sympy.py, which turns every matrix of shape (n, 1) into a list of its entries. That is what callers want when the matrix stands for a vector (e.g. a solution vector), but not when the result is itself a matrix. A fix probably needs the callers that want a vector to ask for it explicitly.

Found on master (4aa7411). Transpose alone is fixed in #2007, since it does not need SymPy at all.

🤖 Generated with Claude Code

Activity

  1. rocky commented on Oct 17, 2026

    @rocky
    Member

    Seems fixed in by PR #2007

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions