There must be an easier way to do this.  In a Python class I have a list 
of RealNumber elements, "fracs_list".  I want to multiply them by a 
common scalar "length" and round them to get a vector of integers.  I 
have tried many permutations of the following code, most of which fail.  
This works, but it's ugly!

answer = vector([Integer(int(round(frac*length))) for frac in fracs_list])

ipdb> type(self.var_fracs[0])
<type 'sage.rings.real_mpfr.RealNumber'>

ipdb> type(length)
<type 'sage.rings.integer.Integer'>

ipdb> type(length * fracs_list[0])
<type 'sage.rings.real_mpfr.RealNumber'>

ipdb> type(round(length * fracs_list[0]))
<type 'float'>

ipdb> Integer(round(length * fracs_list[0]))

ipdb> answer = vector([round(frac*length) for frac in fracs_list])
*** TypeError: unable to find a common ring for all elements

ipdb> answer = vector([int(round(frac*length)) for frac in fracs_list])
*** TypeError: unable to find a common ring for all elements

ipdb> answer = vector([Integer(round(frac*length)) for frac in fracs_list])
*** TypeError: unable to coerce element to an integer

ipdb> answer = vector(IntegerRing(), [round(frac*length) for frac in 
fracs_list])
*** TypeError: unable to coerce element to an integer

Any suggestions on how to get this computation without less than the 
round and two type conversions?

Thanks!

---
Ryan Hinton
[EMAIL PROTECTED]

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to