I think you can do tt = 2 .== (EDGES[ii] .<= X) + (X .< EDGES[ii+1]) which
I find clearer because the dots signal a broadcast operation.

2014-11-16 19:24 GMT-05:00 Ras Jon <[email protected]>:

> Hej,
> I've already posted this as issue on Github and got sent here.
>
> """
> Hej,
> I was expecting the second command to have the same output as the third.
> Is this feasible?
>
> julia> X=rand(3,1)
> 3x1 Array{Float64,2}:
>  0.371312
>  0.438901
>  0.767117
> julia> X<0.5
> ERROR: `isless` has no method matching isless(::Array{Float64,2},
> ::Float64)
>  in < at operators.jl:32
> julia> X.<fill(0.5,5)
> 3x1 BitArray{2}:
>   true
>   true
>   false
> PS: Matlab does it that way ;)
> """
>
> I may have to be more specific. I am creating a histogram function (see
> below) and I think the line
>
> tt = fill(2,length(X)) .==
> (fill(EDGES[ii],length(X)).<=X)+(X.<fill(EDGES[ii+1],length(X)))
>
> would be neater and clearer
> <http://www.dict.cc/englisch-deutsch/clearer.html> like this
>
> tt = 2 == (EDGES[ii] <= X) + (X < EDGES[ii+1])
>
> Why wouldn't that be a feasible implementation?
>
> function histc(X,EDGES)
> counts=zeros(Int16,length(EDGES)-1,1)
> idx=zeros(Int16,length(X),1)
> for ii in 1:length(EDGES)-1
> tt=fill(2,length(X)) .==
> (fill(EDGES[ii],length(X)).<=X)+(X.<fill(EDGES[ii+1],length(X)))
> counts[ii]=sum(tt)
> if counts[ii]!=0
> idx[tt]=fill(ii,counts[ii])
> end
> end
> return counts, idx
> end
>
> Thank you, Ras :)
>
>

Reply via email to