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
-------

Attachment: signature.asc
Description: Digital signature

Reply via email to