Xah Lee wrote:
> On Dec 10, 12:37 pm, [EMAIL PROTECTED] 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
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to