回答編集履歴

1

Numpyを使った場合のサンプルを追加

2017/04/23 23:42

投稿

magichan
magichan

スコア15898

test CHANGED
@@ -23,3 +23,35 @@
23
23
  # -> 84
24
24
 
25
25
  ```
26
+
27
+
28
+
29
+
30
+
31
+ Numpyを使うともう少しシンプルになります。
32
+
33
+
34
+
35
+ ```Python
36
+
37
+ import numpy as np
38
+
39
+
40
+
41
+ M,N = 6,8
42
+
43
+ data = np.reshape(np.arange(M*N), (M, N))
44
+
45
+
46
+
47
+ x0,x1,y0,y1 = 1,3,1,2
48
+
49
+ data_range = data[y0:y0+y1, x0:x0+x1]
50
+
51
+
52
+
53
+ total = data_range.sum()
54
+
55
+ ```
56
+
57
+