[julia-users] Re: Problem with if else in Julia

2015-05-16 Thread paul analyst
You can use [] after a
if a[]<0

works also
Paul

W dniu piątek, 15 maja 2015 23:14:43 UTC+2 użytkownik Lytu napisał:
>
> When i do:
> M=rand(5,5)
> a=M[:,1]' * M[:,1]
> if a<0
> println("Less than 0")
> else
> println("more")
> end
>
> I have an error: " isless has no method matching 
> isless(::Array{Float64,2}, ::Int 32) in < at operators.jl:32
>
> Can anyone tell me please how to do this? Thank you
>


[julia-users] Re: Problem with if else in Julia

2015-05-16 Thread David P. Sanders


El viernes, 15 de mayo de 2015, 16:14:43 (UTC-5), Lytu escribió:
>
> When i do:
> M=rand(5,5)
> a=M[:,1]' * M[:,1]
> if a<0
> println("Less than 0")
> else
> println("more")
> end
>
> I have an error: " isless has no method matching 
> isless(::Array{Float64,2}, ::Int 32) in < at operators.jl:32
>
Perhaps quite not you want this time, but 

a .< 0

returns a matrix of the same size as a, with true or false doing the 
comparison of each entry.

David.

 

> Can anyone tell me please how to do this? Thank you
>


[julia-users] Re: Problem with if else in Julia

2015-05-16 Thread Lytu
Thank you Jeff Waller, it works

On Friday, 15 May 2015 23:22:33 UTC+2, Jeff Waller wrote:
>
> Well I think the problem here is that though M[:,1]' * M[:,1] has only 1 
> value, it's still a (1x1) matrix, and not a scalar.
> What happens when you change to this?
>
> a=(M[:,1]' * M[:,1])[1]
>
> related.  is automatically converting a 1x1 matrix to a scalar or defining 
> comparison between 1x1 matrices and scalars reasonable?
>
> On Friday, May 15, 2015 at 5:14:43 PM UTC-4, Lytu wrote:
>>
>> When i do:
>> M=rand(5,5)
>> a=M[:,1]' * M[:,1]
>> if a<0
>> println("Less than 0")
>> else
>> println("more")
>> end
>>
>> I have an error: " isless has no method matching 
>> isless(::Array{Float64,2}, ::Int 32) in < at operators.jl:32
>>
>> Can anyone tell me please how to do this? Thank you
>>
>

Re: [julia-users] Re: Problem with if else in Julia

2015-05-15 Thread Christian Peel
I've also noticed this.  Let's say a = 1, ix = [1].  So a[ix] gives an
error while a[1] and a[a] do not give errors.  In Matlab, there is no
difference between the type of a and ix, while in other languages there
is.In Matlab a([1]) doesn't produce an error, while in Julia a[[1]]
does.

I'm not certain if this is just something that we have to live with, or if
there is some other solution.

chris


On Fri, May 15, 2015 at 2:22 PM, Jeff Waller  wrote:

> Well I think the problem here is that though M[:,1]' * M[:,1] has only 1
> value, it's still a (1x1) matrix, and not a scalar.
> What happens when you change to this?
>
> a=(M[:,1]' * M[:,1])[1]
>
> related.  is automatically converting a 1x1 matrix to a scalar or defining
> comparison between 1x1 matrices and scalars reasonable?
>
>
> On Friday, May 15, 2015 at 5:14:43 PM UTC-4, Lytu wrote:
>>
>> When i do:
>> M=rand(5,5)
>> a=M[:,1]' * M[:,1]
>> if a<0
>> println("Less than 0")
>> else
>> println("more")
>> end
>>
>> I have an error: " isless has no method matching
>> isless(::Array{Float64,2}, ::Int 32) in < at operators.jl:32
>>
>> Can anyone tell me please how to do this? Thank you
>>
>


-- 
chris.p...@ieee.org


[julia-users] Re: Problem with if else in Julia

2015-05-15 Thread Jeff Waller
Well I think the problem here is that though M[:,1]' * M[:,1] has only 1 
value, it's still a (1x1) matrix, and not a scalar.
What happens when you change to this?

a=(M[:,1]' * M[:,1])[1]

related.  is automatically converting a 1x1 matrix to a scalar or defining 
comparison between 1x1 matrices and scalars reasonable?

On Friday, May 15, 2015 at 5:14:43 PM UTC-4, Lytu wrote:
>
> When i do:
> M=rand(5,5)
> a=M[:,1]' * M[:,1]
> if a<0
> println("Less than 0")
> else
> println("more")
> end
>
> I have an error: " isless has no method matching 
> isless(::Array{Float64,2}, ::Int 32) in < at operators.jl:32
>
> Can anyone tell me please how to do this? Thank you
>