In master Julia the result is 3. I must have changed that when I
reorganised the norm code. I think that 3 is the right answer anyway. In
Julia [1 2 3] is a 1x3 matrix, i.e. not a vector. If you want it to behave
as a vector, make it a vector. This causes some confusion when coming from
MATLAB, but it is only in the transition until you get used to `Vector`s. I
also think that having matrix and vector norm in the same function is the
natural solution in Julia where so much is about dispatch.


2014-03-04 1:45 GMT+01:00 Miguel Bazdresch <eorli...@gmail.com>:

> In Julia 0.2.1, I get 6.0.
>
> -- mb
>
>
> On Mon, Mar 3, 2014 at 7:22 PM, Carlos Becker <carlosbec...@gmail.com>wrote:
>
>> My mistake there, I meant the L1 norm, re-typed:
>>
>> -----------------------------
>> X= [[1 2 3],[4 5 6]]
>>
>> # now, X[1,:] is 1x3 array, containing 1 2 3
>>
>> # but let's peek at its L1-norm:
>> norm( X[1,:], 1 )   #  --> we get 3, where I would expect 6 (1+2+3)
>> -----------------------------
>>
>> can you try that on v0.2? I am on 0.3 from upstream.
>>
>>
>> ------------------------------------------
>> Carlos
>>
>>
>> On Tue, Mar 4, 2014 at 1:19 AM, Patrick O'Leary <patrick.ole...@gmail.com
>> > wrote:
>>
>>> This is odd, as I get norm() working just fine with any of a row,
>>> column, or vector, and all getting exactly the same result of 3.741...
>>> (v0.2.0, on julia.forio.com, since it's quick for me to get to). Note
>>> that it will return the L2 norm by default, exactly as MATLAB does.
>>> Supplying a second argument with p in it (norm([1 2 3], 1)) will return the
>>> p-norm, exactly like MATLAB.
>>>
>>>
>>> On Monday, March 3, 2014 6:12:53 PM UTC-6, Carlos Becker wrote:
>>>>
>>>> Hello all,
>>>>
>>>> today I fought for an hour with a very simple piece of code, of the
>>>> kind:
>>>>
>>>> -----------------------------
>>>> X= [[1 2 3],[4 5 6]]
>>>>
>>>> # now, X[1,:] is 1x3 array, containing 1 2 3
>>>>
>>>> # but let's peek at its L1-norm:
>>>> norm( X[1,:] )   #  --> we get 3, where I would expect 6 (1+2+3)
>>>> -----------------------------
>>>>
>>>> I believe this comes back to the 'how 1xN matrices should be handled'.
>>>> The point is that the current behaviour is totally non-intuitive for
>>>> someone coming from Matlab,
>>>> and having matrix and vector norms in the same function hides this (in
>>>> this case) unwanted behavior.
>>>>
>>>> I am not sure what is the right way to deal with this, but seems like a
>>>> hard wall that more than one
>>>> will hit when coming from matlab-like backgrounds.
>>>>
>>>> Cheers.
>>>>
>>>
>>
>


-- 
Med venlig hilsen

Andreas Noack Jensen

Reply via email to