Ask Your Question

Revision history [back]

For entries in different rings, you could use a nested list. The numpy array data structure is similar, with slightly more functionality (like a transpose method). The latex formatting for numpy arrays probably isn't what you want though, so you can use a simple loop to print the data in the format you want. Here's an example:

sage: ints = primes_first_n(5)
sage: floats = [random() for _ in range(5)]
sage: rats = [1/n for n in range(5,10)]
sage: polys = [x^n for n in range(2,7)]

sage: from numpy import array
sage: mat = array([ints, floats, rats, polys]).transpose()
sage: mat
array([[2, 0.996565962529, 1/5, x^2],
       [3, 0.803053692297, 1/6, x^3],
       [5, 0.870364288574, 1/7, x^4],
       [7, 0.369733125378, 1/8, x^5],
       [11, 0.0361132712282, 1/9, x^6]], dtype=object)

sage: for row in mat:
....:     print ' & '.join([latex(_) for _ in row]) + ' \\\\'
....:     
2 & 0.996565962529 & \frac{1}{5} & x^{2} \\
3 & 0.803053692297 & \frac{1}{6} & x^{3} \\
5 & 0.870364288574 & \frac{1}{7} & x^{4} \\
7 & 0.369733125378 & \frac{1}{8} & x^{5} \\
11 & 0.0361132712282 & \frac{1}{9} & x^{6} \\