For example, 1 1⍷0 0 1 1 1 1 1 0 0 gives 0 0 1 1 1 1 0 0 0, but I want 0 0 1 0 1 0 0 0 0, just like how searching for 11 in 001111100 with regex would work.
Could just be me... If I run RIDE_INIT http:*:8888 dyalog in the terminal, cause an infinite loop in the browser client and then kill the terminal, dyalog persists in the background... At least on Linux
… And it only works for searching for length 2 strings. The idea is basically what I said above. Scans in APL are right folds which I have a harder time picturing. This translates a left fold scan of < into a right fold scan. `<` turns every other 1 in a string of ones to zero as a left scan.
I thought there was a way to do nonoverlapping stencil but a quick scan of the docs didn’t turn up anything. Nor did APLcart. Obviously stencil has the potential to work for longer strings and so probably preferable.
Ahh.. It’s pretty clear when you don’t do a quick scan: “ In general, the right operand g is a 2- row matrix of positive non-zero integers with up to ⍴⍴Y columns. The first row contains the rectangle sizes, the second row the movements i.e. how much to move the rectangle in each step. If g is a scalar or vector it specifies the rectangle size and the movement defaults to 1.”
Actually, this seems to depend on the parity of the index of the first 1. I.e. put a zero in front and your steps might not pick up the right ones.
The magic of the scan version is it doesn’t matter where the cluster of ones is.
Here multiplying by the predicate kills ones that are too close. Once you’re not too close the max picks up the next one. The take the unique at the end.
It works on indices so you’ll have to reconstruct the mask if that’s what you want.
@rak1507 Not sure if it’s deep but @dzaima pointed out that <\ as a left scan is {x+x*y}\ which is perhaps surprisingly useful. I used it in the post just above.
I'm not sure a leading axis definition makes sense. While we can use TAO to pick the middle 1 or two major cells, and we can take the average of two major cells, the two definitions are fundamentally incompatible.
Are we there yet?
See you next week for 2016-3: Statistics - Mode, and don't forget that we'll begin to start two hours earlier (at 15:00 UTC) in 5 weeks.