Michael hktyz2 wrote:
> Thank you all for your kind reply to my questions! Your replys are
> really helpful to me.
(Be warned that my responses contained a number of mistakes,
including some I've not isolated yet in "avg1d_simple". I plead
lack of sleep, and lack of understanding of the problem domain.)
> 1. I intentionally use "a" on both the left and right side and use
> the average value for a(i-1) to compute the value for a(i). I want
> to see if J has any convenient way to implement this kind of
> recursively defined arrays.
...
> 3. The program convolves in the first dimension, which represents the
> time dimension. Suppose that I always want to convolve in the
> time dimension, but the time dimension might be different dimensions
> in arrays.
...
> I am wondering if the program can be implemented in J that is generic
> with respect to the position of the time dimension.
Ok, sure, if that's what you really want.
Here's how I might approach writing this generically:
ripple=: conjunction define
'width rO'=.n NB. rO: range offset
dO=. i.width NB. dO: domain offset
for_j. i.(#y)-width-1 do.
y=. (u(j+dO){y) (j+rO)} y
end.
y
)
avg1d=: (+/%#) ripple 3 1
Example:
avg1d 10 1 1 1 1 1 1 1
10 4 2 1.33333 1.11111 1.03704 1.01235 1
If you want to use this on the second dimension, rather than
the first dimension, use the rank operator: avg1d"_1 data
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm