Ask Your Question

Is there a reliable way to check if an object is a vector?

asked 2020-10-14 17:57:18 +0200

more_weight gravatar image

I'm want to check if a given sage object obj is a vector or not. I'd like to do this as efficiently as possible. Currently my best idea is:


This works, assuming that sage_input is smart enough to identify every vector without false positives. However, this solution feels inefficient (and also inelegant!). Is there a better way?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-10-14 18:06:58 +0200

rburing gravatar image

updated 2020-10-14 18:11:18 +0200

You want is_Vector:

sage: from sage.structure.element import is_Vector
sage: v = vector([1,2,3])
sage: is_Vector(v)
sage: is_Vector([1,2,3])

It checks whether the input is an instance of the abstract element class Vector.

edit flag offensive delete link more


Ha. Had no idea this was built in. Thanks!

more_weight gravatar imagemore_weight ( 2020-10-14 20:37:10 +0200 )edit

Your Answer

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

Add Answer

Question Tools

1 follower


Asked: 2020-10-14 17:57:18 +0200

Seen: 396 times

Last updated: Oct 14 '20