If you actually did want to do it conditionally based on the atom of the bitmask

    operand =. 2 2 2 $ 3 2 2 3 2 3 3 2
   bitmask =. 2 2 2 $ 1 0 0 1 0 1 1 0
   operator =. >:
   bitmask (>:@]^:[)"0 operand  NB. If you insist on doing atomic conditionals
4 2
2 4

2 4
4 2
   operand + bitmask   NB. simpler and, to me, closer to a J way of doing it 
(suggested by Roger as I was writing!)
4 2
2 4

2 4
4 2

Hope this helps,

Cheers, bob

> On Aug 16, 2020, at 13:11, Raoul Schorer <raoul.scho...@gmail.com> wrote:
> 
> Thanks, works perfectly! Now I'll have a good think and try to understand
> how this works ;-)
> 
> On Sun, Aug 16, 2020 at 10:02 PM Roger Hui <rogerhui.can...@gmail.com>
> wrote:
> 
>> If "operator" is >: there is a very easy solution:
>> 
>>   desired_result -: operand + bitmask
>> 1
>> 
>> For a general monadic function, you can do as follows:
>> 
>>   desired_result -: bitmask 0&(] operator)"0 operand
>> 1
>> 
>> The basic idea is what the power operator does; m&v or v&m allows you to do
>> the same when the bitmask is an array and not a scalar.
>> 
>> 
>> 
>> 
>> On Sun, Aug 16, 2020 at 12:45 PM Raoul Schorer <raoul.scho...@gmail.com>
>> wrote:
>> 
>>> Hi,
>>> 
>>> This seems pretty trivial, but I'm stuck on how to perform conditional
>>> application of a verb on a multidimensional array as defined by a bitmask
>>> of the same shape as the operand array. Is there a typical idiom for
>> that?
>>> 
>>> For example,
>>> 
>>> operand =. 2 2 2 $ 3 2 2 3 2 3 3 2
>>> 
>>> bitmask =. 2 2 2 $ 1 0 0 1 0 1 1 0
>>> 
>>> operator =. >:
>>> 
>>> desired_result =. 2 2 2 $ 4 2 2 4 2 4 4 2
>>> 
>>> 
>>> I tried looking at the doc, but I wasn't able to formulate a nice
>> solution.
>>> 
>>> 
>>> Thanks!
>>> 
>>> Raoul
>>> ----------------------------------------------------------------------
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>> 
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>> 
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to