For intervals of equal length the adverb onintervals
provides a simpel and general soluntion
a =: 0.11 0.10 0.24 0.9 1.0
onintervals =:1 : 0
:
(<. y%x) u /. y
)
0.1 +/ onintervals a
0.21 0.24 0.9 1
0.1 +/ onintervals a
0.21 0.24 0.9 1
0.1 (+/%#) onintervals a
0.105 0.24 0.9 1
Fraser
----- Original Message -----
From: "Brian Schott" <[EMAIL PROTECTED]>
To: "Programming forum" <[email protected]>
Sent: Friday, April 27, 2007 4:54 AM
Subject: Re: [Jprogramming] subtotals
In connection with using I. to produce histograms I
latched onto an alternative version of I. , Idotr. This I.
alternative seems to produce intervals of the type [) ,
where I. produces intervals of the type (] .
Idotr =: |[EMAIL PROTECTED] ([EMAIL PROTECTED]) ]
sbtb =: Idotr (+//.) ]
Using this definition I get the same result as Don
with
X sbtb Y
1.32 1.96 0.23 2.62 0.22 0.05 2.29 2.49 0.53
Btw, I found that it is wise to make sure that the
intervals in X are extended at both ends, which does not
seem to matter in this case.
(_1,X,2) sbtb Y
1.32 1.96 0.23 2.62 0.22 0.05 2.29 2.49 0.53
On Thu, 26 Apr 2007, Dan Bron wrote:
+ >I believe this will work:
+ >
+ > sbt =: I.&|. +//. ]
+
+ First, it should've been:
+
+ sbt =: (I.~ |.)~ +//. ]
+
+ Second. I guess the length and order of the results from this is
data-dependent.
+
+ The following version is much longer and uglier than the original, but
produces the correct result independent of the length and order of the
data, and even correctly handles data that is not stricly bounded by
[m,n] .
+
+ interval =. (> {:)~ + <:@:#@:[ - (I.~ |.)~
+ range =. interval ,~ _1 , i.@:>:@:#@:[
+ values =. (,~ 0 #~ 2 + #)~
+ rsums =. range +//. values
+ sbt =: }.@:}:@rsums f.
+
+ This could be made simpler and more efficient if you guaruntee that your
data is clamped to [0,n) or (0,n] (particularly the latter).
+
+ -Dan
+ ----------------------------------------------------------------------
+ For information about J forums see http://www.jsoftware.com/forums.htm
+
(B=)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm