No subject


Sat Feb 12 21:31:30 HKT 2011


do, if you're working on parallel ways of applying an arbitrary
function to the parts of a partition. (Which is what it's really all
about.)


On Wed, May 18, 2011 at 7:25 PM, Zsb=E1n Ambrus <ambrus at math.bme.hu> wrote:
> On Tue, May 17, 2011 at 11:08 PM, Ian Clark <earthspotty at gmail.com> wrote=
:
>> I have an array like this (which may be unsorted, and can grow very larg=
e):
>>
>> 1 =A0 =A0 =A0 100
>> 1 =A0 =A0 =A0 100
>> 1 =A0 =A0 =A0 20
>> 1 =A0 =A0 =A0 400
>> 2 =A0 =A0 =A0 30
>> 2 =A0 =A0 =A0 200
>> 2 =A0 =A0 =A0 300
>> 33 =A0 =A0 =A0100
>> 33 =A0 =A0 =A0100
>> 33 =A0 =A0 =A0100
>>
>> I want to collapse it to:
>>
>> 1 =A0 =A0 =A0 620
>> 2 =A0 =A0 =A0 530
>> 33 =A0 =A0 =A0300
>
> On Tue, May 17, 2011 at 11:14 PM, Marshall Lochbaum
> <mlochbaum at raleighcharterhs.org> wrote:
>> The standard solution would be to use key (/.):
>> +//./ |: arr
>
> That, however, does not give the answer Ian asked for. =A0It only gives
> the sums. =A0How would you get a matrix of both the sum and the keys?
>
> Here are some solutions, but there probably is something more elegant.
>
> =A0 arr =3D: _2]\ 1 100 1 100 1 20 1 400 2 30 2 200 2 300 33 100 33 100 3=
3 100
> =A0 (~.@[,.+//.)/ |: arr
> =A01 620
> =A02 530
> 33 300
> =A0 ({."1({.@{.,[:+/{:"1)/.]) arr
> =A01 620
> =A02 530
> 33 300
>
> --
> Ambrus
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>


More information about the Programming mailing list