473,569 Members | 3,035 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

numpy : efficient sum computations

TG
Hi there.

I want to do some intensive computations with numpy, and I'm
struggling a bit to find myyyyy wayyyyyy. Here is the problem :

m and d are two matrices :
m.shape = (x,y,a,b)
d.shape = (a,b)
I want to return
i.shape = (x,y)
with
i[x,y] = sum(m[x,y] * d)
I already found that
m[:,:] * d
will give me a matrix of shape (x,y,a,b) containing the products.

Now I want to sum up on axis 2 and 3. If I do :
(m[:,:] * d).sum(axis=3). sum(axis=2)
it seems like I get my result.

I'm wondering : is this syntax leading to efficient computation, or is
there something better ?

thanks

Thomas

Oct 16 '07 #1
1 1812
TG wrote:
Hi there.

I want to do some intensive computations with numpy, and I'm
struggling a bit to find myyyyy wayyyyyy.
The best place to ask numpy questions is on the numpy mailing list.

http://www.scipy.org/Mailing_Lists
Here is the problem :

m and d are two matrices :
>m.shape = (x,y,a,b)
d.shape = (a,b)

I want to return
>i.shape = (x,y)
with
>i[x,y] = sum(m[x,y] * d)

I already found that
>m[:,:] * d
will give me a matrix of shape (x,y,a,b) containing the products.

Now I want to sum up on axis 2 and 3. If I do :
>(m[:,:] * d).sum(axis=3). sum(axis=2)
it seems like I get my result.

I'm wondering : is this syntax leading to efficient computation, or is
there something better ?
That's about it. There's no need for the [:,:], though.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Oct 16 '07 #2

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

Similar topics

22
1988
by: J | last post by:
Hi I hope the title of this message indicates my question. I am looking for basic array functionality in Python and it turns out that there are all these packages which are somehow related. Some are allegedly discontinued but still seem to get updated. Could we start a discussion about which package will or may or should survive ?
15
2201
by: nikie | last post by:
I'm a little bit stuck with NumPy here, and neither the docs nor trial&error seems to lead me anywhere: I've got a set of data points (x/y-coordinates) and want to fit a straight line through them, using LMSE linear regression. Simple enough. I thought instead of looking up the formulas I'd just see if there isn't a NumPy function that does...
15
2507
by: greg.landrum | last post by:
After using numeric for almost ten years, I decided to attempt to switch a large codebase (python and C++) to using numpy. Here's are some comments about how that went. - The code to automatically switch python stuff over just kind of works. But it was a 90% solution, I could do the rest by hand. Of course, the problem is that then the code...
2
2782
by: robert | last post by:
in Gnuplot (Gnuplot.utils) the input array will be converted to a Numeric float array as shown below. When I insert a numpy array into Gnuplot like that below, numbers 7.44 are cast to 7.0 Why is this and what should I do ? Is this bug in numpy or in Numeric? >>m #numpy array array(, , , ..., ,
18
22378
by: robert | last post by:
Is there a ready made function in numpy/scipy to compute the correlation y=mx+o of an X and Y fast: m, m-err, o, o-err, r-coef,r-coef-err ? Or a formula to to compute the 3 error ranges? -robert PS: numpy.corrcoef computes only the bare coeff:
2
1609
by: eriwik | last post by:
I'm working on an application that performs calculations on triangles of a 3D-model. As part of those computations I have to calculate a value for each pair of triangles and the number of triangles can be quite large (testmodel has 16500 triangles). Each triangle has a ID-number, however the number-range does not start from 0 but usually...
5
4841
by: robert | last post by:
Turning algs for old NumPy modules into numpy code I suffer from this: Upon further processing of returns of numpy calculations, lots of data in an apps object tree will become elementary numpy types. First there is some inefficiency in calculations. And then you get data inflation and questionable dependencies - e.g. with pickle,ZODB,mpi's ......
2
5763
by: lbolla | last post by:
take a look at Python vs Matlab comparison for numerical computations: numerical-computing-matlab-vs-python+numpy+weave it seems that what stated in a previous thread was true! Python+Numpy results as fast as Matlab. any optimization of Numpy code run much faster than Matlab (up to 10 times faster with pyrex).
1
3735
by: Slaunger | last post by:
Hi, This is my first post here, I am looking forward to being here. I have actually posted almost the same question on comp.lang.python: http://groups.google.dk/group/comp.lang.python/browse_thread/thread/2f0e7ee3ad76d5a3/e2eae3719c6e3fe8?hl=en#e2eae3719c6e3fe8 and got some hints at what i could do, but it is a little bit too...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7619
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...
0
8138
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...
0
7983
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...
0
6290
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...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3662
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...
1
2118
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
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.