Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

enumerating contiguous ones in kdb+

Given a list of 0s and 1s, say l: 0 0 1 1 1 0 0 1 1 I would like to get a sequence beginning with 1 for each contiguous set of 1s. Thus the required output should be l: 0 0 1 2 3 0 0 1 2. How can I achieve this in kdb+?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can use scan:

q){y*x+y}scan 0 0 1 1 1 0 0 1 1
0 0 1 2 3 0 0 1 2
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading