Re: round numbers in an array without importing Numeric or Math? - SOLVED, sort of

2006-05-17 Thread Bernhard Herzog
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

round numbers in an array without importing Numeric or Math?

2006-05-16 Thread Lance Hoffmeyer
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

Re: round numbers in an array without importing Numeric or Math?

2006-05-16 Thread Alexander Schmolck
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

Re: round numbers in an array without importing Numeric or Math?

2006-05-16 Thread Lance Hoffmeyer
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:

Re: round numbers in an array without importing Numeric or Math?

2006-05-16 Thread skip
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

Re: round numbers in an array without importing Numeric or Math?

2006-05-16 Thread Dan Sommers
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',

Re: round numbers in an array without importing Numeric or Math? - SOLVED, sort of

2006-05-16 Thread Lance Hoffmeyer
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

Re: round numbers in an array without importing Numeric or Math? - SOLVED, sort of

2006-05-16 Thread Paul McGuire
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] #

Re: round numbers in an array without importing Numeric or Math? - SOLVED, sort of

2006-05-16 Thread Paul McGuire
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] #

Re: round numbers in an array without importing Numeric or Math? - SOLVED, sort of

2006-05-16 Thread Scott David Daniels
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