Don

perhaps you meant?
   (0j1 * &.-. mask) #!. ' ' chars
B E G

~greg
https//picsrp.github.io

--

from: Don Guinn <[email protected]>
to: Programming forum <[email protected]>
date: Apr 16, 2021, 11:49 AM
subject: Re: [Jprogramming] How to choose characters with a boolean mask?

And more interesting things.
   2j1 1 0j1 1#!.'*' 'abcd'
aa*b*d

--

from: Devon McCormick <[email protected]>
to: J-programming forum <[email protected]>
date: Apr 16, 2021, 9:34 AM
subject: Re: [Jprogramming] How to choose characters with a boolean mask?

For replacing the masked characters:
   mask}chars,:'.'        NB. Replace with .s
A.CD.F.HIJKLM
or
   'XYZ' (I.mask)}chars   NB. Replace with specific characters
AXCDYFZHIJKLM

--

from: Jimmy Gauvin <[email protected]>
to: [email protected]
date: Apr 16, 2021, 7:28 AM
subject: Re: [Jprogramming] How to choose characters with a boolean mask?

You might also be interested in the inverse of copy

1 0 0 0 1 0 1 #^:_1 'abc'

a b c

I remember I had a hard time finding expand

--

from: ethiejiesa
reply-to: [email protected]
to: [email protected]
date: Apr 15, 2021, 10:53 PM
subject: Re: [Jprogramming] How to choose characters with a boolean mask?

Is monadic # what you're looking for?

       mask # chars
    BEG

--

from: 'robert therriault'to: [email protected]
date: Apr 15, 2021, 10:52 PM
subject: Re: [Jprogramming] How to choose characters with a boolean mask?

Hi Harvey,

>You are right that you can't use *. but you can use # or { depending on 
>whether you are working with booleans or indices

    chars=. 'ABCDEFGHIJKLM'
   mask=. 0 1 0 0 1 0 1 0 0 0 0 0 0
   mask # chars      NB. use Copy (dyadic #) to choose which
characters get copied
BEG
   I. mask         NB. Indices (monadic I.) returns indices of 1's
1 4 6
   (I. mask) { chars     NB. use From (dyadic {) to select indices
from the character list
BEG

Hope this helps

Cheers, bob

--

from: HH PackRat <[email protected]>
to: [email protected]
date: Apr 15, 2021, 10:38 PM
subject: [Jprogramming] How to choose characters with a boolean mask?

Hello, all!

>I have a list of characters and a boolean list of 1s and 0s.  I thought that I 
>could use the boolean list as a "mask" to choose characters by using "and" 
>(*.).  But the definition in NuVoc basically states that it can only be used 
>with numbers (no literals).

>Here's an example of the kind of thing I'd like to be able to do:

chars=. 'ABCDEFGHIJKLM'
mask=. 0 1 0 0 1 0 1 0 0 0 0 0 0   [boolean values]

mask2=. 0 1 0 0 4 0 6 0 0 0 0 0 0   [positions of boolean values]

>I thought that I could do something like  chars *. mask to get the result BEG. 
> That doesn't work nor does converting the mask to position numbers (mask2) 
>work.  So how *can* I mask the characters? I'd be interested in knowing both 
>the "pure" boolean kind of approach (1s and 0s only) as well as a positional 
>approach that I can use with amending.

>My ultimate goal is actually to amend the masked characters to be a different 
>character(s).  I hope I've given enough information.  (The example, of course, 
>is completely "fake", but I hope it gives the idea of what I'm trying to do.)

Thanks for any help!

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

Reply via email to