Mathematica 7 compares to other languages
Stef Mientki
stef.mientki at gmail.com
Thu Dec 11 13:12:32 EST 2008
Andreas Waldenburger wrote:
> 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.)
>
>
Couldn't we assume that when you doing these kinds of math, there's always
import numpy
or
from numpy import *
is always at the start of the program, so it doesn't belong to the
functional code ?
And for those who use VPython (and thus needs " from visual import *" )
can simply do
a = norm ( v )
cheers,
Stef
More information about the Python-list
mailing list