Mathematica 7 compares to other languages

Andreas Waldenburger geekmail at usenot.de
Thu Dec 11 12:07:51 EST 2008


On Thu, 11 Dec 2008 05:40:45 +0000 Paul Rudin <paul.nospam at rudin.co.uk>
wrote:

> "Dotan Cohen" <dotancohen at gmail.com> writes:
> 
> > 2008/12/10  <w_a_x_man at yahoo.com>:
> >> Ruby:
> >>
> >> def norm a
> >>  s = Math.sqrt(a.map{|x|x*x}.inject{|x,y|x+y})
> >>  a.map{|x| x/s}
> >> end
> >
> > If someone doesn't counter with a Python one-liner then I'm going to
> > port that to brainfuck.
> 
> from numpy.linalg import norm
> 
> :)

This is one line of Python code alright, but it's not a "one-liner" in
the "computes the a normalized vector"-sense (which was the original
challenge, if there ever was one).

If anything, you are now ready to compute the *norm* of a vector in a
subseqent line. (Or, if you must, after a semicolon on the same line.)

:)
/W

-- 
My real email address is constructed by swapping the domain with the
recipient (local part).



More information about the Python-list mailing list