Newsgroups:   comp.lang.apl
Path: watmath!watserv1!utgpu!news-server.csri.toronto.edu!torsqnt!tmsoft!itcyyz!yrloc!intern
From:         loc@yrloc.ipsa.reuter.COM (Leigh Clayton)
Subject:      EEM responds about histograms
Message-ID: <1991Apr4.002028.24603@yrloc.ipsa.reuter.COM>
Sender: intern@yrloc.ipsa.reuter.COM (Intern via QUADRAM)
X-Telephone:  +1 (416) 364-5361 Fax +1 (416) 364-2910 Telex 0622259
Organization: Reuter:file Ltd.
X-Mail:       1900/2 First Canadian Place, Toronto, Canada, M5X 1E3
Date:          2 Apr 91 16:17:14 UT

 I pass the following along from Eugene McDonnell on IPSA mailbox...
--------------------------------------------------------------------------

no. 5065227 filed  1.46.50  tue  2 apr 1991
from eem
to   loc
cc   jig
subj histogram

Given an array y of nonnegative integers, with maximum value x-1,
a histogram h giving the number of occurrences of each possible
value in the array may be obtained in J by:

    h =. <: , #/.~ (,y),i. x

By JOINING to the RAVEL of y a vector (i. x) of all possible
values, we are insured that the result contains a slot for each
possible value, whether it appears in y or not. This argument is
used (by virtue of the DUPLICATE adverb ~) as left and right
argument to COUNT (#) by KEY (/.), giving a count of the
occurrences of each possible value in the argument (the argument
is its own key). RAVELLING this and SUBTRACTING 1 (<:) from it
(to allow for the presence of i. x in the argument, which should
not add to the count) gives the desired result.

-----------------------------------------------------------
loc@tmsoft.UUCP                     uunet!mnetor!tmsoft!loc
loc@yrloc.ipsa.reuter.COM                   (Leigh Clayton)
