質問編集履歴
2
事例を追加しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -73,3 +73,221 @@
|
|
73
73
|
|
74
74
|
|
75
75
|
```
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
【追加質問です】
|
80
|
+
|
81
|
+
6次元のデータを使った例です。
|
82
|
+
|
83
|
+
numpy の場合、out = x.transpose(0, 4, 5, 1, 2, 3) です。
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
```JavaScript
|
88
|
+
|
89
|
+
<script>
|
90
|
+
|
91
|
+
// 例 x:入力 6次元配列(1x1x3x3x4x4)
|
92
|
+
|
93
|
+
// -> out :出力 6次元配列(1x4x4x1x3x3) へ軸変換
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
x=[
|
98
|
+
|
99
|
+
[[
|
100
|
+
|
101
|
+
// *
|
102
|
+
|
103
|
+
[
|
104
|
+
|
105
|
+
[
|
106
|
+
|
107
|
+
[1,1,1,1],
|
108
|
+
|
109
|
+
[1,1,1,1],
|
110
|
+
|
111
|
+
[1,1,1,1],
|
112
|
+
|
113
|
+
[1,1,1,1],
|
114
|
+
|
115
|
+
],
|
116
|
+
|
117
|
+
[
|
118
|
+
|
119
|
+
[1,1,1,1],
|
120
|
+
|
121
|
+
[1,1,1,1],
|
122
|
+
|
123
|
+
[1,1,1,1],
|
124
|
+
|
125
|
+
[1,1,1,1],
|
126
|
+
|
127
|
+
],
|
128
|
+
|
129
|
+
[
|
130
|
+
|
131
|
+
[1,1,1,1],
|
132
|
+
|
133
|
+
[1,1,1,1],
|
134
|
+
|
135
|
+
[1,1,1,1],
|
136
|
+
|
137
|
+
[1,1,1,1],
|
138
|
+
|
139
|
+
],
|
140
|
+
|
141
|
+
],
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
// **
|
146
|
+
|
147
|
+
[
|
148
|
+
|
149
|
+
[
|
150
|
+
|
151
|
+
[1,1,1,1],
|
152
|
+
|
153
|
+
[1,1,1,1],
|
154
|
+
|
155
|
+
[1,1,1,1],
|
156
|
+
|
157
|
+
[1,1,1,1],
|
158
|
+
|
159
|
+
],
|
160
|
+
|
161
|
+
[
|
162
|
+
|
163
|
+
[1,1,1,1],
|
164
|
+
|
165
|
+
[1,1,1,1],
|
166
|
+
|
167
|
+
[1,1,1,1],
|
168
|
+
|
169
|
+
[1,1,1,1],
|
170
|
+
|
171
|
+
],
|
172
|
+
|
173
|
+
[
|
174
|
+
|
175
|
+
[1,1,1,1],
|
176
|
+
|
177
|
+
[1,1,1,1],
|
178
|
+
|
179
|
+
[1,1,1,1],
|
180
|
+
|
181
|
+
[1,1,1,1],
|
182
|
+
|
183
|
+
],
|
184
|
+
|
185
|
+
],
|
186
|
+
|
187
|
+
// ***
|
188
|
+
|
189
|
+
[
|
190
|
+
|
191
|
+
[
|
192
|
+
|
193
|
+
[1,1,1,1],
|
194
|
+
|
195
|
+
[1,1,1,1],
|
196
|
+
|
197
|
+
[1,1,1,1],
|
198
|
+
|
199
|
+
[1,1,1,1],
|
200
|
+
|
201
|
+
],
|
202
|
+
|
203
|
+
[
|
204
|
+
|
205
|
+
[1,1,1,1],
|
206
|
+
|
207
|
+
[1,1,1,1],
|
208
|
+
|
209
|
+
[1,1,1,1],
|
210
|
+
|
211
|
+
[1,1,1,1],
|
212
|
+
|
213
|
+
],
|
214
|
+
|
215
|
+
[
|
216
|
+
|
217
|
+
[1,1,1,1],
|
218
|
+
|
219
|
+
[1,1,1,1],
|
220
|
+
|
221
|
+
[1,1,1,1],
|
222
|
+
|
223
|
+
[1,1,1,1],
|
224
|
+
|
225
|
+
],
|
226
|
+
|
227
|
+
],
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
]]
|
232
|
+
|
233
|
+
]
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
console.log(x)
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
let out = []
|
242
|
+
|
243
|
+
for (let d0 = 0 ; d0 < x.length; d0++){//1
|
244
|
+
|
245
|
+
out[d0] = []
|
246
|
+
|
247
|
+
for (let d1 = 0 ; d1 < x[0][0][0][0].length ; d1++){//4
|
248
|
+
|
249
|
+
out[d0][d1] = []
|
250
|
+
|
251
|
+
for (let d2 = 0 ; d2 < x[0][0][0][0][0].length ; d2++){//4
|
252
|
+
|
253
|
+
out[d0][d1][d2] = []
|
254
|
+
|
255
|
+
for (let d3 = 0 ; d3 < x[0].length ; d3++){//1
|
256
|
+
|
257
|
+
out[d0][d1][d2][d3] = []
|
258
|
+
|
259
|
+
for (let d4 = 0 ; d4 < x[0][0].length ; d4++){//3
|
260
|
+
|
261
|
+
out[d0][d1][d2][d3][d4] = []
|
262
|
+
|
263
|
+
for (let d5 = 0 ; d5 < x[0][0][0].length ; d5++){//3
|
264
|
+
|
265
|
+
console.log(`out[${d0}][${d1}][${d2}][${d3}][${d4}][${d5}] = ${x[d0][d4][d5][d1][d2][d3]}`);
|
266
|
+
|
267
|
+
out[d0][d1][d2][d3][d4][d5] = x[d0][d4][d5][d1][d2][d3]
|
268
|
+
|
269
|
+
}
|
270
|
+
|
271
|
+
}
|
272
|
+
|
273
|
+
}
|
274
|
+
|
275
|
+
}
|
276
|
+
|
277
|
+
}
|
278
|
+
|
279
|
+
}
|
280
|
+
|
281
|
+
console.log(out)
|
282
|
+
|
283
|
+
</script>
|
284
|
+
|
285
|
+
```
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
実行すると、
|
290
|
+
|
291
|
+
Uncaught TypeError: Cannot read property '0' of undefined
|
292
|
+
|
293
|
+
のエラーでストップします。
|
1
例題の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,9 +6,11 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
-
|
9
|
+
```JavaScript
|
10
10
|
|
11
|
+
// 例 x:入力
|
12
|
+
|
11
|
-
|
13
|
+
x=[
|
12
14
|
|
13
15
|
[
|
14
16
|
|
@@ -35,3 +37,39 @@
|
|
35
37
|
]
|
36
38
|
|
37
39
|
]
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
// 出力:out
|
44
|
+
|
45
|
+
// 初期化
|
46
|
+
|
47
|
+
let out = []
|
48
|
+
|
49
|
+
for (let d0 = 0 ; d0 < x[0][0].length; d0++){
|
50
|
+
|
51
|
+
out[d0] = []
|
52
|
+
|
53
|
+
for (let d1 = 0 ; d1 < x[0][0][0].length ; d1++){
|
54
|
+
|
55
|
+
out[d0][d1] = []
|
56
|
+
|
57
|
+
for (let d2 = 0 ; d2 < x.length ; d2++){
|
58
|
+
|
59
|
+
out[d0][d1][d2] = []
|
60
|
+
|
61
|
+
for (let d3 = 0 ; d3 < x[0].length ; d3++){
|
62
|
+
|
63
|
+
out[d0][d1][d2][d3] = 0
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
```
|