Either of these: >+&.>/<"1 i. 2 5 5 7 9 11 13 >+&.>/<"1 i. 5 0 1 2 3 4
dos=: ] ` (+/) @. (2=[:#$) dos i. 5 0 1 2 3 4 dos i. 2 5 5 7 9 11 13 The latter is probably more efficient. On 2/18/08, Leigh J. Halliwell <[EMAIL PROTECTED]> wrote: > > Dear J Forum: > > I am applying +/ to arrays that can be of either rank 1 or rank 2. The > following approach works fine for rank 2: > > +/ i. 2 5 > 5 7 9 11 13 > > But for a rank 1 array, I want just the array itself. I can do that with > +/"_1: > > +/"_1 i. 5 > 0 1 2 3 4 > > However +/"_1 i.2 5 collapses along the wrong axis: > > +/"_1 i.2 5 > 10 35 > > Please show me an efficient summation operator that will leave untouched > rank 1 arrays, but will perform +/ on rank 2 arrays. Preferably I will > not > have to add a leading axis to the rank 1 arrays. Thank you > > Sincerely, > > Leigh > > > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > -- Devon McCormick, CFA ^me^ at acm. org is my preferred e-mail ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
