473,288 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,288 software developers and data experts.

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 1809
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
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....
15
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...
15
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...
2
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...
18
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? ...
2
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...
5
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...
2
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...
1
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: ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.