ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 01 Feb 2013 07:01:04 +0100check whether object is matrixhttps://ask.sagemath.org/question/9757/check-whether-object-is-matrix/Hi,
I would like to check whether an object is a sage matrix. I thought that "isinstance" might help, however isinstance is a little bit too sensitive for my purpose as the following example shows:
m1=matrix([1.])
print type(m1)
print isinstance(m1, sage.matrix.matrix_generic_dense.Matrix_generic_dense)
m1=matrix([1])
print type(m1)
isinstance(m1, sage.matrix.matrix_generic_dense.Matrix_generic_dense)
returns
<type 'sage.matrix.matrix_generic_dense.Matrix_generic_dense'>
True
<type 'sage.matrix.matrix_integer_dense.Matrix_integer_dense'>
False
I would however like to obtain a function which recognizes a matrix regardless to the types of its entries.
isinstance(m1,matrix)
doesn't work either but gives the error: "isinstance() arg 2 must be a class, type, or tuple of classes and types"
So what else can I do?
Thanks for your answers,
TobiastwchFri, 01 Feb 2013 07:01:04 +0100https://ask.sagemath.org/question/9757/Abstract base classeshttps://ask.sagemath.org/question/8352/abstract-base-classes/Python has a module named abc for implementing "abstract base classes", see http://www.python.org/dev/peps/pep-3119/ for definitions and usage. Why is it not used in Sage ?
Example: if type(i) is 'int', isinstance (i, Integer) should be True (today it's False).BétrémaFri, 30 Sep 2011 14:12:06 +0200https://ask.sagemath.org/question/8352/