Paul McGuire [EMAIL PROTECTED] writes:
... or if you prefer the functional approach (using map)...
roundToInt = lambda z : int(z+0.5)
Topamax = map( roundToInt, map( float, map(str, Topamax) ) )
(Python also has a built-in round() function, but this returns floats, not
ints - if that is
Is there an easy way to round numbers in an array?
I have
Test = [1.1,2.2,3.7]
and want to round so the values are
print Test [1,2,4]
Lance
--
http://mail.python.org/mailman/listinfo/python-list
Lance Hoffmeyer [EMAIL PROTECTED] writes:
Is there an easy way to round numbers in an array?
I have
Test = [1.1,2.2,3.7]
and want to round so the values are
print Test [1,2,4]
[int(x+0.5) for x in Test]
'as
--
http://mail.python.org/mailman/listinfo/python-list
May have a complicating issue with the array? Have
the numbers have been interpreted as strings? I have
been pulling them from a Word doc using regex's
print Test
[u'9.0', u'58.6', u'97.8', u'10.0', u'9.6', u'28.1']
Lance
Alexander Schmolck wrote:
Lance Hoffmeyer [EMAIL PROTECTED] writes:
Lance May have a complicating issue with the array? Have the numbers
Lance have been interpreted as strings? I have been pulling them from
Lance a Word doc using regex's
[int(float(x)+0.5) for x in Test]
S
--
http://mail.python.org/mailman/listinfo/python-list
On Tue, 16 May 2006 13:41:37 -0500,
Lance Hoffmeyer [EMAIL PROTECTED] wrote:
May have a complicating issue with the array? Have
the numbers have been interpreted as strings? I have
been pulling them from a Word doc using regex's
print Test
[u'9.0', u'58.6', u'97.8', u'10.0', u'9.6',
The array comes out as unicode. This is probably because I am grabbing the
numbers
from a Word Doc using regex's.
So, before rounding I perform the following:
# Convert to String
Topamax = [str(x) for x in Topamax]
# Convert to floating
Topamax = [float(x) for x in Topamax]
# Finally, round the
Lance Hoffmeyer [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
The array comes out as unicode. This is probably because I am grabbing
the numbers
from a Word Doc using regex's.
So, before rounding I perform the following:
# Convert to String
Topamax = [str(x) for x in Topamax]
#
Lance Hoffmeyer [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
The array comes out as unicode. This is probably because I am grabbing
the numbers
from a Word Doc using regex's.
So, before rounding I perform the following:
# Convert to String
Topamax = [str(x) for x in Topamax]
#
Paul McGuire wrote:
... or if you prefer the functional approach (using map)...
roundToInt = lambda z : int(z+0.5)
Topamax = map( roundToInt, map( float, map(str, Topamax) ) )
Somehow, the list comprehension looks simpler and clearer to me:
Topamax = [int(float(uni) + .5) for uni in
10 matches
Mail list logo