On Monday, November 17, 2014 12:02:07 PM UTC-6, Eka Palamadai wrote:
>
> I don't know what matlab does.
>
> As a user, ones(n,1) and ones(n) both return me a vector, and it is
> confusing to find that ones(n,1) != ones(n).
>
As Andreas and Tim have tried to say, your claim that "ones(n,1) and
ones(n) both return me a vector" is incorrect.
julia> ones(3,1)
3x1 Array{Float64,2}:
1.0
1.0
1.0
julia> ones(3)
3-element Array{Float64,1}:
1.0
1.0
1.0
The first is a matrix with 3 rows and 1 column. The second is a vector.
That's why they are not equal.
> On Monday, November 17, 2014 12:53:25 PM UTC-5, Tim Holy wrote:
>>
>> What's intuitive is very dependent upon your background. If you're coming
>> from
>> Matlab, for example, "everything is a matrix" and Matlab does this
>> extraordinarily-confusing thing:
>>
>> ones(3,3,3) gives me a 3d array;
>> ones(3,3) gives me a 2d array;
>> but
>>
>> >> ones(3)
>>
>> ans =
>>
>> 1 1 1
>> 1 1 1
>> 1 1 1
>>
>> Why the heck did it give me a 2d matrix when I asked for a 1-dimensional
>> vector of 1s?
>>
>> Julia is much more consistent: the dimensionality of the created object
>> is
>> equal to the number of indices you supply. If you ask for something
>> that's
>> 3x1, that's the size you'll get out; perforce, that is a 2d array.
>>
>> --Tim
>>
>>
>>
>> On Monday, November 17, 2014 09:41:10 AM Eka Palamadai wrote:
>> > "which I think is reasonable" is a subjective argument.
>> > It would be helpful if the type system is intuitive and non-confusing
>> to
>> > programmers.
>> >
>> > On Monday, November 17, 2014 12:24:58 PM UTC-5, Andreas Noack wrote:
>> > > Semantically, ones(n,1) creates a vector and not a matrix.
>> > >
>> > > I'd rather say that in MATLAB ones(n,1) creates a vector.
>> > >
>> > > This has been discussed many times on the list and in issues. In
>> > > particular, see the famous
>> https://github.com/JuliaLang/julia/issues/4774
>> > > .
>> > >
>> > > In Julia, Vector{T} and Matrix{T} are aliases for Array{T,1} and
>> > > Array{T,2} which I think is reasonable. The questions are to what
>> extend a
>> > > nx1 Matrix should work similarly to a Vector and a Vector should work
>> > > similarly to a nx1 Matrix. That is the discussion in the issue
>> mentioned,
>> > > and it is actually more subtle than one would expect.
>> > >
>> > > 2014-11-17 12:04 GMT-05:00 Eka Palamadai <[email protected]
>> <javascript:>>
>> > >
>> > >> Semantically, ones(n,1) creates a vector and not a matrix.
>> > >> Why is ones(n,1) different from ones(n)?
>> > >> The type system is very confusing and non-intuitive.
>> > >>
>> > >> On Sunday, November 16, 2014 7:28:28 PM UTC-5, Andreas Noack wrote:
>> > >>> The input should be two Vectors, but your first argument is a
>> Matrix
>> > >>>
>> > >>> 2014-11-16 19:25 GMT-05:00 Eka Palamadai <[email protected]>:
>> > >>>> SymTridiagonal does not seem to work properly.
>> > >>>>
>> > >>>> For e.g, the following snippet fails.
>> > >>>>
>> > >>>> julia> n=10 ;
>> > >>>> A=SymTridiagonal(2*ones(n,1), -1*ones(n-1));
>> > >>>> ERROR: `convert` has no method matching
>> > >>>> convert(::Type{SymTridiagonal{T}},
>> > >>>>
>> > >>>> ::Array{Float64,2}, ::Array{Float64,1})
>> > >>>>
>> > >>>> in call at base.jl:34
>> > >>>>
>> > >>>> Any thoughts?
>>
>>