comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Efficiently multiplying an array by a vector
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Efficiently multiplying an array by a vector [message #93673] Tue, 27 September 2016 18:38 Go to previous message
laura.hike is currently offline  laura.hike
Messages: 87
Registered: September 2013
Member
The following text is a slightly edited version of a post by Mark Plonski several years ago that was never answered. Just saving typing time because my problem is the same. In fact, it seems like it must be a common problem when one tries to vectorize and speed up a program.


What is the most efficient way to multiply every col in a 2D array
(ncol x nrow) by a vector of length (ncol)?

Example:

input array vector output array

a11 a12 a13 b1 a11b1 a12b1 a13b1
a21 a22 a23 b2 a21b2 a22b2 a23b2


This could be done by looping over the cols:

FOR i=0,ncol-1 DO c[i,*] = a[i,*] * b

Is there a more efficient way (w.r.t. computational speed) to do this?

I know I could replicate the column vector into a matrix (b # identity row)
and then do a ptwise matrix multiply, but my matrices can
be very large (1M elements) and I occasionally run out of swap
space. I don't know if that would run any faster anyway.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Meaning of the assignment
Next Topic: Contour labels in IDL 8.0

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 11:33:34 PDT 2025

Total time taken to generate the page: 0.00489 seconds