First time here? Check out the FAQ!

Ask Your Question
0

Check if object is a matrix

asked 12 years ago

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?)

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 12 years ago

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.

Preview: (hide)
link

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: 12 years ago

Seen: 581 times

Last updated: Apr 07 '12