MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Why Does Repeated Dot Product Take So Long?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg67949] Re: [mg67938] Why Does Repeated Dot Product Take So Long?
  • From: "Carl K. Woll" <carlw at wolfram.com>
  • Date: Tue, 18 Jul 2006 05:50:34 -0400 (EDT)
  • References: <200607171051.GAA02347@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Gregory Lypny wrote:
> Hello Everyone,
> 
> x and y are both 2000 x 3 matrices.  I wanted to created a 2000 x 1  
> vector with each element equal to the dot product of the  
> corresponding rows of x and y.  So I tried this:
> 
> Table[x[[i]].y[[i]], {i, 1, 2000}]
> 
> It took more than two and a half minutes on my iBook G4.  Is that  
> normal?  I've done seemingly more demanding computations in Do loops  
> and Tables that are completed in a split second.  Am I doing  
> something wrong with this one?
> 
> Regards,
> 
> 	Gregory

When I tried your code with matrices containing machine reals, the 
timing was practically instantaneous. Perhaps you could tell us what the 
matrix elements are.

For this particular computation with very large numerical matrices, a 
faster approach is to rely on the listable attribute of matrices:

Total[Transpose[x y]]

For large matrices such as 200000 x 3 the above method is significantly 
faster.

Carl Woll
Wolfram Research


  • Prev by Date: Re: Filtering same elements from two lists
  • Next by Date: Re: Why Does Repeated Dot Product Take So Long?
  • Previous by thread: Re: Why Does Repeated Dot Product Take So Long?
  • Next by thread: Re: Why Does Repeated Dot Product Take So Long?