It is called interval index (dyad I.), please see help
documentation for detail.

    2.5 5 7.5 I. 1 3 3 3 4 7 7 8 8 9
0 1 1 1 1 2 2 3 3 3
    #/.~ 2.5 5 7.5 I. 1 3 3 3 4 7 7 8 8 9
1 4 2 3


Вс, 08 май 2016, dahn oak написал(а):
> 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

-- 
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
gpg --keyserver subkeys.pgp.net --armor --export 4434BAB3
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to