473,503 Members | 3,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Numeric speed


I have been looking at the speed of Python with the Numeric module by simulating
some random numbers and computing some statistics. Here is the code. Line
(1) is replaced as shown
in the table.

from RandomArray import random
from Numeric import sum
n = 1000000
m = 10
for i in range(m):
xx = random(n)
print xx[n-1] # (1)

The times shown are in seconds and are the lowest values from several runs.

line (1) Python Fortran
xx[n-1] 1.33 0.52
sum(xx) 1.43 0.54
sum(xx**1) 3.76 0.54
sum(xx**2) 3.71 0.54
sum with explicit loop 11.79 0.54

My conclusions are that
(1) Using the sum function of Numeric is much faster than an explicit loop.
(2) Python with Numeric does not recognize that sum(xx**1) reduces
to sum(xx), and this should be fixed. Obviously one would not write xx**1
explicitly in code, but it is possible that a variable exponent could equal
1.
(3) The range of Fortran/Python speeds here is 2.5 to 7.0, when the Numeric
module is used.

The Fortran code is below. Line (1) is replaced as appropriate. The Python

version is 2.3.3 , the Fortran compiler is Compaq Visual Fortran 6.6c, and
the platform is an Intel Pentium 4 2.80 GHz on Windows XP.

program xran_sum
integer, parameter :: n = 1000000, m = 10
real :: xx(n)
integer :: i
call random_seed()
do i=1,m
call random_number(xx)
print*,xx(n) ! (1)
end do
end program xran_sum

Jul 18 '05 #1
0 1274

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1383
by: Ognen Duzlevski | last post by:
Hi, can someone explain how to change a value within an array from a C function? For example, I have the following array: scoremat = zeros((10,10)) and the following C function: PyObject...
0
1384
by: Travis Oliphant | last post by:
Numarray is making great progress and is quite usable for many purposes. An idea that was championed by some is that the Numeric code base would stay static and be replaced entirely by Numarray. ...
3
1799
by: Stephen Boulet | last post by:
I have a long list of floats (1613808 elements long). It takes quite a while to load this into a 7 dimensional Numeric array. Is there any obvious way to speed this up? def...
24
2286
by: Matt Feinstein | last post by:
Hi all-- I'm new to Python, and was somewhat taken aback to discover that the core language lacks some basic numerical types (e.g., single-precision float, short integers). I realize that there...
30
3637
by: Dr John Stockton | last post by:
It has appeared that ancient sources give a method for Numeric Date Validation that involves numerous tests to determine month length; versions are often posted by incomers here. That sort of code...
3
2364
by: daniel.neilson | last post by:
I have two one-dimensional Numeric arrays, and I need to know the indices in the second array of elements from the first. so if i had: a=array() b=array() i want a function match that does...
2
1581
by: jelle | last post by:
I have a function that uses the Numeric module. When I launch the function csrss.exe consumes 60 / 70 % cpu power rather than having python / Numeric run at full speed. Has anyone encountered this...
4
7186
by: Dimitrios Charitatos | last post by:
Hello, I suspect that there is a quite straight forward answer to this, but I can't find it... I want to import an image and extract a matrix (or array) from it with elements showing the RGB...
0
1982
by: robert | last post by:
just a note - some speed comparisons : 0.60627370238398726 0.42836673376223189 0.36965815487747022 0.016557970357098384 0.15692469294117473 0.01951756438393204
0
7261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7315
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7445
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5559
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4665
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1492
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
369
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.