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

Reply via email to