Yep. It's just something that hasn't been implemented yet. David On Tue, Dec 14, 2010 at 07:18, Dan Drake <dr...@kaist.edu> wrote: > diagonal_matrix() does not seem smart enough to deal with 1-dimensional > numpy arrays: > > sage: s > array([ 7.10977223, 2.10977223]) > > Both values are numpy floats: > > sage: [parent(_) for _ in s] > [<type 'numpy.float64'>, <type 'numpy.float64'>] > > But diagonal_matrix() can't make sense of s: > > sage: diagonal_matrix(s) > Traceback (most recent call last): > [...] > UnboundLocalError: local variable 'v' referenced before assignment > > I tried specifying the ring: > > sage: diagonal_matrix(RDF, s) > Traceback (most recent call last): > [...] > ValueError: Invalid matrix constructor. Type matrix? for help > > I also tried making a list out of s: > > sage: diagonal_matrix(RDF, list(s)) > Traceback (most recent call last): > [...] > TypeError: unable to find a common ring for all elements > > (That's an unusual error, since both elements coerce into Sage float > types with no problem.) > > Finally I got it to work, by doing everything myself: > > sage: diagonal_matrix([RDF(_) for _ in s]) > [7.10977222865 0.0] > [ 0.0 2.10977222865] > > The usual matrix() function deals with numpy arrays with no problem, so > I expected diagonal_matrix() to do so as well. Should diagonal_matrix() > "Just Work" when given numpy arrays? > > Dan > > -- > --- Dan Drake > ----- http://mathsci.kaist.ac.kr/~drake > ------- > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.10 (GNU/Linux) > > iEYEARECAAYFAk0HYJoACgkQr4V8SljC5Lpz6ACeLl4cut4TsOO5MiMAhZKWCWrA > FMoAnjkndsTtkkNhRAGioWzTlSkGQTpd > =NybY > -----END PGP SIGNATURE----- > >
-- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org