문제

I have a function that rotates a vector v of length 9 by offset in groups of 3:

∇ r ← offset rot3 v
    r ← , offset ⌽ 3 3 ⍴ v
∇

It seems to work:

      2 rot3 ⍳ 9
3 1 2 6 4 5 9 7 8

And then a function that rotates a 9x9 matrix m horizontally by offset in groups of 3:

∇ r ← offset rot3h m
    r ← ⊃ offset rot3¨ ,/ m
∇

This seems to work, too:

      a ← 2 rot3h 9 9 ⍴ ⍳ 81
      a
 3  1  2  6  4  5  9  7  8
12 10 11 15 13 14 18 16 17
21 19 20 24 22 23 27 25 26
30 28 29 33 31 32 36 34 35
39 37 38 42 40 41 45 43 44
48 46 47 51 49 50 54 52 53
57 55 56 60 58 59 63 61 62
66 64 65 69 67 68 72 70 71
75 73 74 78 76 77 81 79 80
      ⍴ a
9 9

Now I want to build a vector that contains a given matrix rotated by 1, 2 and 3 (which is the identity, but nevermind):

So I tried this (thinking: "Make the outer product of two vectors, the first containing 1, 2 and 3; the second containing a"):

a ← 9 9 ⍴ ⍳ 81
1 2 3 ∘.rot3h ⊂a

Unfortunately, the result of this is:

      a ← 9 9 ⍴ ⍳ 81
      1 2 3 ∘.rot3h ⊂a
 2  3  1  5  6  4  8  9  7   1 1 1 1 1 1 1 1 1  1 1 1 1 1 1 1 1 1 
 11 12 10 14 15 13 17 18 16                                        
 20 21 19 23 24 22 26 27 25                                        
 29 30 28 32 33 31 35 36 34                                        
 38 39 37 41 42 40 44 45 43                                        
 47 48 46 50 51 49 53 54 52                                        
 56 57 55 59 60 58 62 63 61                                        
 65 66 64 68 69 67 71 72 70                                        
 74 75 73 77 78 76 80 81 79                                        

Could someone please explain me where my reasoning went haywire?

도움이 되었습니까?

해결책

Try

  1 2 3 rot3h¨⊂a

Enclosing a has the effect of turning it into a scalar, then you can succesively apply 1, 2, and 3 rot3h by scalar extension. (1 + 2 3 4 extends 1 such that it is added to all elements of 2 3 4)

Back to the original expression, when using outer product, the intuitive expectation would be that you get a matrix of matrices back. As the right argument is scalar and the expected result a vector of matrices, using each might be more natural.

Having said that, your original expression worked correctly and returned the same result in Dyalog APL.

Good example - I would report this bug to the GNU APL developers.

다른 팁

I am getting this with SVN version 4525 of GNU APL 1.1:

∇ r ← offset rot3 v
[1]     r ← , offset ⌽ 3 3 ⍴ v
[2] ∇

      ∇ r ← offset rot3h m
[1]     r ← ⊃ offset rot3¨ ,/ m
[2] ∇

      a ← 9 9 ⍴ ⍳ 81
      1 2 3 ∘.rot3h ⊂a
  2  3  1  5  6  4  8  9  7    3  1  2  6  4  5  9  7  8 
 11 12 10 14 15 13 17 18 16   12 10 11 15 13 14 18 16 17 
 20 21 19 23 24 22 26 27 25   21 19 20 24 22 23 27 25 26 
 29 30 28 32 33 31 35 36 34   30 28 29 33 31 32 36 34 35 
 38 39 37 41 42 40 44 45 43   39 37 38 42 40 41 45 43 44 
 47 48 46 50 51 49 53 54 52   48 46 47 51 49 50 54 52 53 
 56 57 55 59 60 58 62 63 61   57 55 56 60 58 59 63 61 62 
 65 66 64 68 69 67 71 72 70   66 64 65 69 67 68 72 70 71 
 74 75 73 77 78 76 80 81 79   75 73 74 78 76 77 81 79 80 
        1  2  3  4  5  6  7  8  9 
       10 11 12 13 14 15 16 17 18 
       19 20 21 22 23 24 25 26 27 
       28 29 30 31 32 33 34 35 36 
       37 38 39 40 41 42 43 44 45 
       46 47 48 49 50 51 52 53 54 
       55 56 57 58 59 60 61 62 63 
       64 65 66 67 68 69 70 71 72 
       73 74 75 76 77 78 79 80 81
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top