On 04/19/2010 12:58 PM, Bastian Weber wrote:
> The question is: Where should I have found the information about the
> existence of .numpy? And where will the next one with that problem find
> it? Is there something like the scipy cookbook for sage where this could
> be added?
In Sage, you can use tab completion to discover methods:
sage: m=random_matrix(RDF,4,4)
sage: m.<tab>
will list all the methods of m, including m.numpy
I just found that adding this line in the class definition in
matrix_double_dense.pyx:
__array__=numpy
makes it so that this now works:
sage: m=random_matrix(RDF,4,4)
sage: numpy.array(m)
array([[ 0.95041375, -0.93413188, -0.34801206, -0.81931649],
[-0.83999126, -0.35074003, 0.26855088, -0.6917416 ],
[ 0.22118328, -0.24463205, 0.98608149, -0.52649223],
[-0.01629823, 0.22644043, -0.29993975, -0.46477457]])
sage: numpy.array(m).dtype
dtype('float64')
which is certainly more natural (for a numpy person) than m.numpy()
(note that numpy.array(m) worked before, but gave back an array with
python objects, while the float64 array is more natural for matrices
over RDF).
This patch is now up at
http://trac.sagemath.org/sage_trac/ticket/8719
and is ready for review!
Thanks,
Jason