On 4/13/07, Henry Rich <[EMAIL PROTECTED]> wrote:

I can't quite figure out what you're up to.  I note that

   ((i.#q) { q) -: q
1

is almost a tautology, so I dont know why you have
((i.#q) { q)   instead of   q.


Here's my guess, assuming the above is a tautology.
First, start by looking at the shapes; note that "desiredResult"
has a shape of 120 and is text, probably not really what we
want.

NB. Assume we want numeric matrix as result:
  desiredResult =: ".&>}:<;._1 LF,(0 : 0)
0 1 2 3
0 2 1 3
0 3 1 2
0 1 2 4
0 2 1 4
0 4 1 2
0 1 3 4
0 3 1 4
0 4 1 3
0 2 3 4
0 3 2 4
0 4 2 3
1 2 3 4
1 3 2 4
1 4 2 3
)

NB. To work with arrays in J, start by looking at the shapes.

  $desiredResult
15 4
  $&.>desiredResult;q;c
+----+---+---+
|15 4|3 4|5 4|
+----+---+---+
  desiredResult;q;c
+-------+-------+-------+
|0 1 2 3|0 1 2 3|0 1 2 3|
|0 2 1 3|0 2 1 3|0 1 2 4|
|0 3 1 2|0 3 1 2|0 1 3 4|
|0 1 2 4| |0 2 3 4|
|0 2 1 4| |1 2 3 4|
|0 4 1 2| | |
|0 1 3 4| | |
|0 3 1 4| | |
|0 4 1 3| | |
|0 2 3 4| | |
|0 3 2 4| | |
|0 4 2 3| | |
|1 2 3 4| | |
|1 3 2 4| | |
|1 4 2 3| | |
+-------+-------+-------+

  15=(#q)*#c
1
NB. It looks like we may want to apply each row of q to each row of c.

  q{"1/c NB. Use each row ("1) of q on each (/) row of c
0 1 2 3
0 1 2 4
0 1 3 4
0 2 3 4
1 2 3 4

0 2 1 3
0 2 1 4
0 3 1 4
0 3 2 4
1 3 2 4

0 3 1 2
0 4 1 2
0 4 1 3
0 4 2 3
1 4 2 3
   desiredResult;q{"1/c NB. Looks like correct items but not same order...
+-------+-------+
|0 1 2 3|0 1 2 3|
|0 2 1 3|0 1 2 4|
|0 3 1 2|0 1 3 4|
|0 1 2 4|0 2 3 4|
|0 2 1 4|1 2 3 4|
|0 4 1 2| |
|0 1 3 4|0 2 1 3|
|0 3 1 4|0 2 1 4|
|0 4 1 3|0 3 1 4|
|0 2 3 4|0 3 2 4|
|0 3 2 4|1 3 2 4|
|0 4 2 3| |
|1 2 3 4|0 3 1 2|
|1 3 2 4|0 4 1 2|
|1 4 2 3|0 4 1 3|
| |0 4 2 3|
| |1 4 2 3|
+-------+-------+
  $q{"1/c          NB. Again, start by looking at the shape: the
3 5 4                NB. desired result begins with the first row
  $1 0 2|:q{"1/c NB. of each plane...
5 3 4
1 0 2|:q{"1/c
0 1 2 3
0 2 1 3
0 3 1 2

0 1 2 4
0 2 1 4
0 4 1 2

0 1 3 4
0 3 1 4
0 4 1 3

0 2 3 4
0 3 2 4
0 4 2 3

1 2 3 4
1 3 2 4
1 4 2 3

  $,/1 0 2|:q{"1/c NB. So, collapse first two dimensions...
15 4
  desiredResult-:,/1 0 2|:q{"1/c
1

--
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to