Mathematica 7 compares to other languages

Jon Harrop jon at ffconsultancy.com
Wed Dec 10 23:23:54 CET 2008


Xah Lee wrote:
> On Dec 10, 12:37 pm, w_a_x_... at yahoo.com wrote:
>> Ruby:
>>
>> def norm a
>>   s = Math.sqrt(a.map{|x|x*x}.inject{|x,y|x+y})
>>   a.map{|x| x/s}
>> end
> 
> I don't know ruby, but i tried to run it and it does not work.
> 
> #ruby
> def norm a
>   s = Math.sqrt(a.map{|x|x*x}.inject{|x,y|x+y})
>   a.map{|x| x/s}
> end
> 
> v = [3,4]
> 
> p norm(v) # returns [0.6, 0.8]

That is the correct answer.

> The correct result for that input would be 5.

No, you're confusing normalization with length.

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?u



More information about the Python-list mailing list