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: [mg67962] Re: [mg67938] Why Does Repeated Dot Product Take So Long?
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Tue, 18 Jul 2006 05:51:06 -0400 (EDT)
  • Reply-to: hanlonr at cox.net
  • Sender: owner-wri-mathgroup at wolfram.com

Unless your matrices are symbolic, it should go pretty fast.

$Version

5.2 for Mac OS X (June 20, 2005)

n=2000;
x=Table[Random[],{n},{3}];
y=Table[Random[],{n},{3}];

Timing[sol1=Table[x[[i]].y[[i]], {i, n}];]

{0.007042 Second,Null}

Timing[sol2=#[[1]].#[[2]]&/@Thread[{x,y}];]

{0.028243 Second,Null}

Timing[sol3=Dot@@@Thread[{x,y}];]

{0.04984 Second,Null}

Timing[sol4=MapThread[Dot,{x,y}];]

{0.047926 Second,Null}

sol1==sol2==sol3==sol4

True


Bob Hanlon

---- Gregory Lypny <gregory.lypny at videotron.ca> 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
> 


  • 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?