Thanks Henry,
Not as simple as I thought it might/should be but nicer than what I was using!
It also fixes the bug in my code that reversed the order of the result.
(<rnge) fns respectively> data
+--------------+--------------+--------------+-------------------+
| 2 1 0 _1 _2| 1 2 3 4 5| 7 8 9 10 11| 3 1.5 1 0.75 0.6|
|11 10 9 8 7| 5 10 15 20 25|23 24 25 26 27|12 6 4 3 2.4|
|20 19 18 17 16| 9 18 27 36 45|39 40 41 42 43|21 10.5 7 5.25 4.2|
|29 28 27 26 25|13 26 39 52 65|55 56 57 58 59|30 15 10 7.5 6|
|38 37 36 35 34|17 34 51 68 85|71 72 73 74 75|39 19.5 13 9.75 7.8|
+--------------+--------------+--------------+-------------------+
> From: Henry Rich
>
> This has been a recurring problem. The best that I have is due to
> Martin Neitzel: (watch line wrap)
>
> NB. u is gerund, v is a verb. [x] (k{u)`:0 &. v is applied to cell k
> of y
> NB. The first cell is evaluated to get the shape of a result cell, then
> all cells are reevaluated
> respectively =: 2 : 0
> a: (<@:((,'2')&(,&<))@:((<,']')&,) "0 u) respectively v y
> :
> z =. (#y) $ ,: x ({.m)`:0&.v {.y
> for_y. y do. z =. (x (((#m)|y_index){m)`:0 &.v y) y_index} z end.
> )
>
>
> Henry Rich
>
> Sherlock, Ric wrote:
> > Can anybody provide some guidance on the following?
> >
> > fns=: ((-~ +/)"1)`((*~ +/)"1)`((+~ +/)"1)`((%~ +/)"1)
> > rnge=. >: i. 5
> > ]data=. (i.5 3);(i.5 2);(i.5 4);(i.5 3)
> > +--------+---+-----------+--------+
> > | 0 1 2|0 1| 0 1 2 3| 0 1 2|
> > | 3 4 5|2 3| 4 5 6 7| 3 4 5|
> > | 6 7 8|4 5| 8 9 10 11| 6 7 8|
> > | 9 10 11|6 7|12 13 14 15| 9 10 11|
> > |12 13 14|8 9|16 17 18 19|12 13 14|
> > +--------+---+-----------+--------+
> >
> > Given the gerund "fns" (4 dyadic verbs) and the noun "data" (4 arrays
> which are the desired arguments for the corresponding verbs in the
> gerund), how can I apply the verbs to their respective arguments such
> that:
> >
> > rnge applyVerbs data
> > +-------------------+--------------+--------------+--------------+
> > | 3 1.5 1 0.75 0.6| 7 8 9 10 11| 1 2 3 4 5| 2 1 0 _1 _2|
> > |12 6 4 3 2.4|23 24 25 26 27| 5 10 15 20 25|11 10 9 8 7|
> > |21 10.5 7 5.25 4.2|39 40 41 42 43| 9 18 27 36 45|20 19 18 17 16|
> > |30 15 10 7.5 6|55 56 57 58 59|13 26 39 52 65|29 28 27 26 25|
> > |39 19.5 13 9.75 7.8|71 72 73 74 75|17 34 51 68 85|38 37 36 35 34|
> > +-------------------+--------------+--------------+--------------+
> >
> > Here is a looping explicit solution, but I feel like should be a
> simpler/better way?
> >
> > applyVerbs=: 3 : 0
> > (>: i. 4) applyVerbs y
> > :
> > res=. ''
> > for_mod. y do.
> > res=. res ;~ x [email protected]_index >mod
> > end.
> > }:res
> > )
> >
> > For those interested in the actual problem - the verbs are different
> models that are being compared. Different models have different numbers
> of inputs (the columns of arrays in data) and the rows of the arrays in
> data are different suggested input combinations. I'm going to multiplot
> the result. Eg:
> > require 'plot'
> > pd 'reset'
> > pd 'multi 2 2 , 2 2'
> > pd (<'type line;'),.rnge makeFuncData data
> > pd 'show'
> >
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm