~: y (Nub Sieve)
A boolean vector relating a given vector to its Nub (~.).
It has 1 for the first occurrence of each unique element, and 0 for a repeated element.
z=: 'abracadabra' ~.z NB. Nub z abrcd ~:z NB. Nub Sieve z 1 1 1 0 1 0 1 0 0 0 0
Common uses
1. Wherever data is held in 2 parallel lists, Nub Sieve (~:) yields a vector capable of pruning the second list to match the Nub (~.) of the first.
NAME=: 'Joe' ; 'Bob' ; 'Jim' ; 'Mary' ; 'Jim' AGE=: 25 60 32 21 33 z=. ~: NAME ] z=. ~: NAME NB. "sieve" to apply to AGE 1 1 1 1 0 ] NAME=: ~. NAME +---+---+---+----+ |Joe|Bob|Jim|Mary| +---+---+---+----+ ] AGE=: z # AGE 25 60 32 21
See Also
Nub (~.)
Entry in the J Dictionary for ~:
x ~: y (Not-Equal)
The boolean result of comparing two items, or lists of items.
See the J Dictionary for the tolerance rules governing equality between numbers. By default the tolerance is 2^_44 when recognizing two numbers as being "equal" under =.
]z=: i.5 0 1 2 3 4 3 ~: z 1 1 1 0 1 z ~: z 0 0 0 0 0 z ~: |.z 1 1 0 1 1
Not-Equal (~:) works between boxed items too:
z=: 'alpha' ; 'bravo' ; 'charlie' z ~: |.z 1 0 1 z ~: <'bravo' 1 0 1
To avoid x~:y giving length error, the Shape Of ($) x and y must follow the rules for Plus (+).
Common uses
1. To construct criteria for conditional expressions in verb definitions
if. '.' ~: y do. return. end. NB. instead of: if. -. '.' = y do. return. end.
See Also
Equal (=)
Entry in the J Dictionary for ~:
