It looks like you have vectorized ifelse, the operator version just doesn't
work. This code is on line 379 of operators.jl
function ifelse(c::AbstractArray{Bool}, x, y)
reshape([ifelse(ci, x, y) for ci in c], size(c))
end
If I do
ifelse((1:10 .< 5) , 1 , 0)
then everything works.
however
(1:10 .< 5) ? 1 : 0
does not. I'm not sure why.
Also it appears that ifelse is not automatically imported like the rest of
the operators from base are.
On Friday, June 6, 2014 10:58:10 PM UTC-4, Stefan Karpinski wrote:
>
> We should probably vectorize the ifelse function.
>
> On Jun 6, 2014, at 10:51 PM, David Einstein <[email protected]
> <javascript:>> wrote:
>
> sqrt(x.^2 .+ y.^2) .< radius
> is a vector of booleans
>
> ?:
> expects a boolean
>
> you probably want something like:
>
> inside_disc(x,y,radius) = map(good -> good ? 1 : 0,
> sqrt(x.^2+y.^2).<radius)
>
>
>
> On Friday, June 6, 2014 10:18:36 PM UTC-4, Zahirul ALAM wrote:
>>
>> When I pass two arrays the function returns:
>>
>> type: non-boolean (BitArray{1}) used in boolean context while loading
>> In[10], in expression starting on line 1
>>
>>
>> I have modified the function to address the element wise operation as
>> follows:
>>
>>
>> inside_disc(x,y,radius) = sqrt(x.^2 .+ y.^2) .< radius ? 1 : 0
>>
>> seems to me that the error is being thrown by .< operation. What am I
>> missing?
>>
>>
>> On Friday, 6 June 2014 20:34:22 UTC-4, Miguel Bazdresch wrote:
>>>
>>> I'm not sure I understand the question. Do you mean something like this?
>>>
>>> inside_disc(x,y,radius) = sqrt(x^2+y^2)<radius ? 1 : 0
>>>
>>> -- mb
>>>
>>>
>>> On Fri, Jun 6, 2014 at 8:28 PM, Zahirul ALAM <[email protected]>
>>> wrote:
>>>
>>>> I guess one can do a for loop. But how do I vectorize the code?
>>>>
>>>>
>>>> On Friday, 6 June 2014 20:27:46 UTC-4, Zahirul ALAM wrote:
>>>>>
>>>>> How would one implement a step function like behaviour in julia? In
>>>>> mathematica one can write the following to create a circle with value of
>>>>> 1
>>>>> within the radius and 0 outside
>>>>>
>>>>> UnitBox[Sqrt[X^2 + Y^2]*0.5/radius];
>>>>>
>>>>> X and Y are the coordinates.
>>>>>
>>>>
>>>