Well... splitSubs2=: i.@#@] </.~ +/\@[ I. (i.%])@#@]
is a bit more concise. But it also partitions slightly different. Would you be too bothered by that, or not? (Note also, though, since we are not concerned with the contents of X, only with its length, we could simplify this expression slightly if we made the length of X be its splitSubs' right argument.) Thanks, -- Raul On Fri, Oct 20, 2017 at 4:42 AM, 'Jon Hough' via Programming <[email protected]> wrote: > The problem: > Let X be an array. > X=: i. 50 NB. example > > Let 'split' be the percentages that each subarray takes from X, sequentially > e.g > split =: 0.35 0.35 0.3 NB. first array takes 35% , second sub array takes > 35%, third takes 30% > So in the end > > My solution > > splitSubs =: -.~&.>/\@:(i.&.>"0@:<"0)@:}.@:>.@:((+/\ - ])@:[ (* , ]) #@:]) > > split splitSubs X > > > This gives 3 boxed arrays. Each array holds the indices to take from X. > > There is a slight problem in that the first and second subarrays have > different > length, due to rounding error. I am not too bothered about that since, > depending on the size of X and the percentages, this is > unavoidable. > > Any more succinct, nicer solutions? > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
