473,782 Members | 2,554 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(x x)
print*,xx(n) ! (1)
end do
end program xran_sum

Jul 18 '05 #1
0 1291

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

Similar topics

3
1394
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 *DynAlign(PyObject *self, PyObject *args)
0
1420
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. However, Numeric is currently used in a large installed base. In particular SciPy uses Numeric as its core array. While no doubt numarray arrays will be supported in the future, the speed of the less bulky Numeric arrays and the typical case...
3
1818
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 insertData(self,data): # Start off with an array of the desired size # "self.MEASURED", etc., are integers arrayData = zeros(, Float64)
24
2324
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 are extensions that add these types-- But what's the rationale for leaving them out? Have I wandered into a zone in the space/time continuum where people never have to read binary data files? Matt Feinstein
30
3695
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 seems unnecessarily long. For some while, the following approach has been given here :- function ValidDate(y, m, d) { // m = 0..11 ; y m d integers, y!=0
3
2376
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 this:
2
1588
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 problem before? It seriously messes up my Numeric performance. I'm running 2.4.2 on xp. Cheers, Jelle
4
7197
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 value of each pixel. But I want to be able to do this with all types of image formats. It was suggested that a function such as 'B = numeric.from_image(A)' was used but I can't find it in any of the libraries. I was hoping you could help me on this....
0
1999
by: robert | last post by:
just a note - some speed comparisons : 0.60627370238398726 0.42836673376223189 0.36965815487747022 0.016557970357098384 0.15692469294117473 0.01951756438393204
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10308
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10143
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9939
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8964
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5375
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5507
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4040
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 we have to send another system
3
2870
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.