回答編集履歴

2

修正

2021/12/30 06:54

投稿

ppaul
ppaul

スコア24670

test CHANGED
@@ -6,30 +6,102 @@
6
6
 
7
7
  違います。
8
8
 
9
- axis=0とaxis=1は、rollする軸です。
9
+ axis=は、rollする軸です。3次元とかで考えてみたほうが理解しやすいと思います。
10
10
 
11
11
 
12
12
 
13
13
  ```python
14
14
 
15
- >>> a = np.arange(6).reshape(2,3)
15
+ >>> a = np.arange(60).reshape(3,4,5)
16
-
17
- >>> print(a)
18
-
19
- [[0 1 2]
20
-
21
- [3 4 5]]
22
16
 
23
17
  >>> np.roll(a, 1, axis=0)
24
18
 
25
- array([[3, 4, 5],
19
+ array([[[40, 41, 42, 43, 44],
26
20
 
21
+ [45, 46, 47, 48, 49],
22
+
27
- [0, 1, 2]])
23
+ [50, 51, 52, 53, 54],
24
+
25
+ [55, 56, 57, 58, 59]],
26
+
27
+
28
+
29
+ [[ 0, 1, 2, 3, 4],
30
+
31
+ [ 5, 6, 7, 8, 9],
32
+
33
+ [10, 11, 12, 13, 14],
34
+
35
+ [15, 16, 17, 18, 19]],
36
+
37
+
38
+
39
+ [[20, 21, 22, 23, 24],
40
+
41
+ [25, 26, 27, 28, 29],
42
+
43
+ [30, 31, 32, 33, 34],
44
+
45
+ [35, 36, 37, 38, 39]]])
28
46
 
29
47
  >>> np.roll(a, 1, axis=1)
30
48
 
31
- array([[2, 0, 1],
49
+ array([[[15, 16, 17, 18, 19],
32
50
 
51
+ [ 0, 1, 2, 3, 4],
52
+
53
+ [ 5, 6, 7, 8, 9],
54
+
55
+ [10, 11, 12, 13, 14]],
56
+
57
+
58
+
59
+ [[35, 36, 37, 38, 39],
60
+
61
+ [20, 21, 22, 23, 24],
62
+
63
+ [25, 26, 27, 28, 29],
64
+
65
+ [30, 31, 32, 33, 34]],
66
+
67
+
68
+
69
+ [[55, 56, 57, 58, 59],
70
+
71
+ [40, 41, 42, 43, 44],
72
+
73
+ [45, 46, 47, 48, 49],
74
+
33
- [5, 3, 4]])
75
+ [50, 51, 52, 53, 54]]])
76
+
77
+ >>> np.roll(a, 1, axis=2)
78
+
79
+ array([[[ 4, 0, 1, 2, 3],
80
+
81
+ [ 9, 5, 6, 7, 8],
82
+
83
+ [14, 10, 11, 12, 13],
84
+
85
+ [19, 15, 16, 17, 18]],
86
+
87
+
88
+
89
+ [[24, 20, 21, 22, 23],
90
+
91
+ [29, 25, 26, 27, 28],
92
+
93
+ [34, 30, 31, 32, 33],
94
+
95
+ [39, 35, 36, 37, 38]],
96
+
97
+
98
+
99
+ [[44, 40, 41, 42, 43],
100
+
101
+ [49, 45, 46, 47, 48],
102
+
103
+ [54, 50, 51, 52, 53],
104
+
105
+ [59, 55, 56, 57, 58]]])
34
106
 
35
107
  ```

1

例を追加

2021/12/30 06:54

投稿

ppaul
ppaul

スコア24670

test CHANGED
@@ -6,4 +6,30 @@
6
6
 
7
7
  違います。
8
8
 
9
- axis=0とaxis=1は、rotateする軸です。
9
+ axis=0とaxis=1は、rollする軸です。
10
+
11
+
12
+
13
+ ```python
14
+
15
+ >>> a = np.arange(6).reshape(2,3)
16
+
17
+ >>> print(a)
18
+
19
+ [[0 1 2]
20
+
21
+ [3 4 5]]
22
+
23
+ >>> np.roll(a, 1, axis=0)
24
+
25
+ array([[3, 4, 5],
26
+
27
+ [0, 1, 2]])
28
+
29
+ >>> np.roll(a, 1, axis=1)
30
+
31
+ array([[2, 0, 1],
32
+
33
+ [5, 3, 4]])
34
+
35
+ ```