Hello, I want to mimic this Mathematica code:
BinCounts[x, {div}]
It returns an array where i-th element is a count of elements in x that
belongs to interval [div_i, div_i+1).
I've succeeded, but want to know if my soulution is adequate enough in terms
of J programming style. Here it is:
(/:~ x) ((</ }.) +/@:*. (>:/ }:)) div
Example:
] x =: /:~ ? 10 # 10
1 3 3 3 4 7 7 8 8 9
x ((</ }.) +/@:*. (>:/ }:)) 0 2.5 5 7.5 _
1 4 2 3
It's a histogram
1 = # 1 NB. (>:&0 *. <&2.5)
4 = # 3 3 3 4 NB. (>:&2.5 *. <&5 )
2 = # 7 7 NB. (>:&5 *. <&7.5)
3 = # 8 8 9 NB. (>:&7.5 *. <&_ )
The main concern is that the }. and {: makes array copies, as far as I know.
Can I do better, more J-ish solution?
──
dahn oak <[email protected]>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm