Integer From A Float List?!?

A

andrea_gavana

Hello NG,

sorry to bother you again with this question... I never used the "timeit"
function, and I would like to ask you if the call I am doing is correct:

C:\Python23\Lib>python timeit.py -n 1000 -s "from Numeric import ones" -s
"floa
ts=ones((1000,1),'f')" -s "ints = floats.astype(int)"
1000 loops, best of 3: 0.0536 usec per loop

I used Numeric module to create a 1000 floats matrix of ones, and it seems
to me that is a lot faster than other solutions... but probably I am doing
something wrong in my call to the timeit function...

Thank you a lot.

Andrea.
 
K

Kent Johnson

Hello NG,

sorry to bother you again with this question... I never used the "timeit"
function, and I would like to ask you if the call I am doing is correct:

C:\Python23\Lib>python timeit.py -n 1000 -s "from Numeric import ones" -s
"floa
ts=ones((1000,1),'f')" -s "ints = floats.astype(int)"
1000 loops, best of 3: 0.0536 usec per loop

The -s option indicates Setup steps that are done outside the timing loop. So you have timed 1000
empty loops, which is indeed impressively fast :)

The correct command is
C:\Python23\Lib>python23 timeit.py -n 1000 -s "from Numeric import ones" -s
"floats=ones((1000,1),'f')" "ints = floats.astype(int)"
1000 loops, best of 3: 30.7 usec per loop

which is still impressively fast compared to map:

C:\Python23\Lib>python timeit.py -s "floats = map(float, range(1000))" "ints= map(int, floats)"
1000 loops, best of 3: 572 usec per loop

Kent
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top