Ask Your Question

Testing if an object is a matrix

asked 2020-09-30 05:04:24 -0500

Thierry Dumont gravatar image

updated 2020-09-30 05:30:44 -0500

slelievre gravatar image

Some time ago, to test if A is a matrix, I just used:

from sage.matrix.matrix import is_Matrix
if is_Matrix(A):

But this is now deprecated. What should I use instead?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2020-09-30 05:18:13 -0500

slelievre gravatar image

updated 2020-09-30 05:29:34 -0500

It's not really the function that was deprecated, but the module it was in.

The same function can now be imported from a different module.

To figure out the new import, one can have a look at

and click on the commit id in the "Branch" field to see the replacements that were made when the module was deprecated.

This is the new import:

from sage.structure.element import is_Matrix

How to figure all that out from scratch:

  • try the initial import:

    sage: from sage.matrix.matrix import is_Matrix
  • then look at the source code of isMatrix:

    sage: is_matrix??
  • this tells you everything happens in the file .../sage/matrix/matrix.pyx

  • in a text editor, open the file <path_to_sage_root_folder>/src/sage/matrix/matrix.pyx

  • in this file there is a note about deprecation and a reference to Sage Trac ticket 24096

  • then see above.

Simpler way to test if something is a matrix:

sage: A = matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
sage: isinstance(A, sage.structure.element.Matrix)
edit flag offensive delete link more

answered 2020-09-30 17:44:01 -0500

Emmanuel Charpentier gravatar image

Alternative :

sage: import_statements("is_Matrix")
from sage.structure.element import is_Matrix


edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2020-09-30 05:04:24 -0500

Seen: 27 times

Last updated: Sep 30