Ask Your Question

Revision history [back]

Unless you need something special about structured arrays, you could just define a new object class:

sage: class UsefulData(SageObject):
....:     def __init__(self,my_float,my_matrix):
....:         self.float = my_float
....:         self.matrix = my_matrix

(I did this at a sage command prompt, but it's better in a notebook cell or in a separate file attached to the sage session. That way you can easily edit and update the class as you do more and more sophisticated things with it.)

sage: R.<s> = PolynomialRing(QQ); R
Univariate Polynomial Ring in s over Rational Field

sage: d1 = UsefulData(pi.n(),matrix([[1, s],[s^2, -1]]))
sage: d1.float
sage: d1.matrix
[  1   s]
[s^2  -1]

sage: d2 = UsefulData(e.n(),matrix([[s^2, s^3],[s^5, s^7]]))
sage: d2.float
sage: d2.matrix
[s^2  s^3]
[s^5  s^7]

There is a further advantage here: if you want to do something with this data, you can attach functions (methods) to the object class too. If computational time or space is an issue, you can convert the expensive parts to cython classes/attributes.