Discussion: Introducing new operators for matrix computation

Gareth McCaughan gjm11 at g.local
Sat Jul 15 18:38:30 EDT 2000


Huaiyu Zhu wrote:
> How would you write this in list compresension (in less than 10 lines)?
> 
> B*(sin(A*x+b).*(A*y)/3)/C
> 
> Note that * is matrix multiplication and .* is elementwise.  Note that C is
> a matrix so the / is matrixwise.  If you want to write everything as for
> loops it takes at least 30 lines, without any decent error analysis.

    B*[p*q/3 for p in A*x+b, q in A*y]/C

(I've forgotten the proposed syntax for comprehension, so that
may be slightly wrong.) I'm not sure what precedences you want
the .* and / operators to have, so it's possible that I really
mean

    B*[p*q for p in A*x+b, q in (A*y)/3]/C ;

of course they evaluate to the same thing anyway.

-- 
Gareth McCaughan  Gareth.McCaughan at pobox.com
sig under construction



More information about the Python-list mailing list