Ask Your Question
0

Check if object is a matrix

asked 2012-04-07 06:22:57 +0100

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
2

answered 2012-04-07 08:28:35 +0100

Volker Braun gravatar image

You can do this:

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

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

Stats

Asked: 2012-04-07 06:22:57 +0100

Seen: 546 times

Last updated: Apr 07 '12