Ask Your Question

Check if object is a matrix

asked 2012-04-06 23:22:57 -0500

chaesloc2 gravatar image

How can I check if something is a matrix?

The best I've come up with so far is:

x in MatrixSpace(SR,n)

But it doesn't work for arbitrary dimension. (Am I right in assuming that SR is the most general thing one can define a matrix over?)

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2012-04-07 01:28:35 -0500

Volker Braun gravatar image

You can do this:

sage: from sage.matrix.matrix import is_Matrix
sage: is_Matrix(1)

Even better, don't check for types in your code. If an argument behaves like a matrix, then your code works. If not, an exception will be raised. Thats how its supposed to work.

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: 2012-04-06 23:22:57 -0500

Seen: 134 times

Last updated: Apr 07 '12