I do really like the idea of this being I.^:_1. A lot of times I have had an
array of indices that I would like to get to an array of 1s, and I have been
forced to use something like (i.n) e. l (list is l, max index is n).
Making I.^:_1 equal to ([: <:@(#/.~) i.@>:@(>./) , ]) would be really
useful.

Marshall

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Zsbán Ambrus
Sent: Sunday, September 05, 2010 3:00 PM
To: [email protected]
Subject: [Jprogramming] Mask from list of indices with multiplicity

If I have a list of indices with possible repetitions, such as

   i=: 1 3 1

how do I convert it to a mask m so that n{m is the number of occurrences of
n in i ?

   m=: +/ i =/ i. >: >./ i
0 2 0 1

I can convert from the mask to the (sorted) list of indices with the I.
builtin, eg.

   I. m
1 1 3

but is there a simpler way for the conversion to mask?  Would it make sense
if I.^:_1 did this?

Ambrus
----------------------------------------------------------------------
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