ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 08 Oct 2012 10:33:33 -0500strings and other objects in matriceshttp://ask.sagemath.org/question/9389/strings-and-other-objects-in-matrices/Hi,
Rather than me starting by creating a thin wrapper around a list of lists and calling it a SpecialMatrix, does anyone have any ideas creating SpecialMatrix class deriving from some base matrix class such that I can load up the matrix with objects in the entries?
Ultimately I would not like to recreate matrix addition and matrix multiplication and instead leverage what's currently in existence.
In the documentation, it specifically says it can pull callable objects. Any tips?http://www.sagemath.org/doc/reference/sage/matrix/constructor.html
Thanks!Thu, 04 Oct 2012 10:27:09 -0500http://ask.sagemath.org/question/9389/strings-and-other-objects-in-matrices/Answer by Jason Grout for <p>Hi, </p>
<p>Rather than me starting by creating a thin wrapper around a list of lists and calling it a SpecialMatrix, does anyone have any ideas creating SpecialMatrix class deriving from some base matrix class such that I can load up the matrix with objects in the entries?</p>
<p>Ultimately I would not like to recreate matrix addition and matrix multiplication and instead leverage what's currently in existence.</p>
<p>In the documentation, it specifically says it can pull callable objects. Any tips?http://www.sagemath.org/doc/reference/sage/matrix/constructor.html</p>
<p>Thanks!</p>
http://ask.sagemath.org/question/9389/strings-and-other-objects-in-matrices/?answer=14120#post-id-14120The entries to a matrix are assumed to belong to a Sage ring structure. You can see various examples of overriding in the matrix/ directory (for example, the matrix_symbolic_dense.pyx).Mon, 08 Oct 2012 10:33:33 -0500http://ask.sagemath.org/question/9389/strings-and-other-objects-in-matrices/?answer=14120#post-id-14120Answer by SLOtoSF for <p>Hi, </p>
<p>Rather than me starting by creating a thin wrapper around a list of lists and calling it a SpecialMatrix, does anyone have any ideas creating SpecialMatrix class deriving from some base matrix class such that I can load up the matrix with objects in the entries?</p>
<p>Ultimately I would not like to recreate matrix addition and matrix multiplication and instead leverage what's currently in existence.</p>
<p>In the documentation, it specifically says it can pull callable objects. Any tips?http://www.sagemath.org/doc/reference/sage/matrix/constructor.html</p>
<p>Thanks!</p>
http://ask.sagemath.org/question/9389/strings-and-other-objects-in-matrices/?answer=14111#post-id-14111`import numpy as np
a = np.array([['apple', 'frog'],[[3,2], 3]], dtype=object); a`
`array([[apple, frog],
[[3, 2], 3]], dtype=object)`
Sage Matrices have entries as ring elements.... so this can be done in numpy instead.Sat, 06 Oct 2012 11:05:37 -0500http://ask.sagemath.org/question/9389/strings-and-other-objects-in-matrices/?answer=14111#post-id-14111