I found all of this a little confusing. Is histogram intended to be a
useful verb to investigate sets of numbers, or just an exercise in
analyzing syntax?
If the former, I find -
]v =. 10 ?...@$ 8
2 4 4 3 2 0 2 5 5 0
histogram v
2 4 4 3 2 0 2 5 5 0
to be not very interesting/useful... While a simpler verb gives a
very useful result, i.e.
hist =: ~. ,: #/.~
hist v
2 4 3 0 5
3 2 1 2 2
NB. 3 twos, 2 fours, 1 three, 2 zeros, and 2 fives.
In some cases, it is "easier to read" if the items are sorted, and
I've made a lot of use of -
shist =: ] {"1~ [: /: 0 { ]
shist hist v
0 2 3 4 5
2 3 1 2 2
At 16:29 +0000 2009/02/20, Steven Taylor wrote:
>histogram=: <: @ (#/.~) @ (i...@#@[ , I.)
>
>0 : 0
>n-line COMMENT
>i...@#@[, put in an ordered list at the start of the
>I. interval list to guarantee that key
> will order its index collections in
> an order that makes sense to a histogram
>
>/.~ make our collection groups
># and then count the number of elements in each
>i...@#@[, the key 'collection' order guarantee technique
> puts our count out by one.
><: bump it down one with the decrement
>
> but, is <: in its monadic or dyadic form?
> Does this come from the @ symbol or the [?
>
> what makes _(#/.~)_ monadic?
>
> (/.~) 0 1 2 0 1 3 3 3 3
>0 0 0 0
>1 1 0 0
>2 0 0 0
>3 3 3 3
> #(/.~) 0 1 2 0 1 3 3 3 3
>2 2 1 4
> How does it work out there are two zeros from this output? Ahh, because J
>pads it with
>zeros to match the longest entry in the array, but the evaluation is prior
>to the padding.
> How does that sound?
> I wish I could improve my J diagnostic skills.
>I didn't make much sense of tree view
>+ couldn't seem to work out definitively when left and right operands are
>used.
>My "technique" consists of reading and rereading definitions carefully.
>I'm still not 100% sure. I don't want to guess.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm