Ask Your Question

Testing if an object is a matrix

asked 2020-09-30 12:04:24 +0200

Thierry Dumont gravatar image

updated 2020-09-30 12:30:44 +0200

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-10-01 00:44:01 +0200

Emmanuel Charpentier gravatar image

Alternative :

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


edit flag offensive delete link more

answered 2020-09-30 12:18:13 +0200

slelievre gravatar image

updated 2020-09-30 12:29:34 +0200

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

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 12:04:24 +0200

Seen: 36 times

Last updated: Sep 30 '20