回答編集履歴
2
コメントを受けて修正
answer
CHANGED
@@ -122,16 +122,16 @@
|
|
122
122
|
# [0, 0, 0, 0, 1, 2, 3, 3, 3]], dtype=int8)
|
123
123
|
|
124
124
|
c1D = np.convolve(b1D, np.array([1, 1, 1]))[:-1].reshape(arr.shape)[:, 2:-1]
|
125
|
-
# array([[1, 2, 3, 2, 1, 0, 1
|
125
|
+
# array([[1, 2, 3, 2, 1, 0, 1],
|
126
|
-
# [1, 0, 1, 2, 3, 2, 1
|
126
|
+
# [1, 0, 1, 2, 3, 2, 1],
|
127
|
-
# [0, 0, 0, 1, 1, 1, 0
|
127
|
+
# [0, 0, 0, 1, 1, 1, 0],
|
128
|
-
# [1, 2, 3, 2, 1, 0, 0
|
128
|
+
# [1, 2, 3, 2, 1, 0, 0],
|
129
|
-
# [1, 1, 1, 0, 0, 0, 0
|
129
|
+
# [1, 1, 1, 0, 0, 0, 0],
|
130
|
-
# [1, 1, 1, 2, 2, 2, 1
|
130
|
+
# [1, 1, 1, 2, 2, 2, 1],
|
131
|
-
# [3, 2, 2, 1, 2, 1, 1
|
131
|
+
# [3, 2, 2, 1, 2, 1, 1],
|
132
|
-
# [1, 1, 1, 1, 2, 2, 3
|
132
|
+
# [1, 1, 1, 1, 2, 2, 3],
|
133
|
-
# [1, 1, 0, 0, 0, 0, 0
|
133
|
+
# [1, 1, 0, 0, 0, 0, 0],
|
134
|
-
# [0, 0, 0, 1, 2, 3, 3
|
134
|
+
# [0, 0, 0, 1, 2, 3, 3]])
|
135
135
|
```
|
136
136
|
|
137
137
|
上記の配列で`3`がある箇所は、連番が4つ続いているということです。
|
1
コメントを受けて修正
answer
CHANGED
@@ -28,7 +28,7 @@
|
|
28
28
|
# [ 1, 3, 6, 8, 11, 21, 22, 23, 24, 25]])
|
29
29
|
|
30
30
|
# その1
|
31
|
-
idx = np.all(np.convolve(np.ediff1d(arr.ravel()) == 1, np.array([1, 1, 1]))[:-1].reshape(arr.shape)[:, 2:] != 3, 1)
|
31
|
+
idx = np.all(np.convolve(np.ediff1d(arr.ravel()) == 1, np.array([1, 1, 1]))[:-1].reshape(arr.shape)[:, 2:-1] != 3, 1)
|
32
32
|
# その2
|
33
33
|
idx = np.all(ndimage.convolve((np.diff(arr) == 1).view(np.int8), np.array([[1, 1, 1]])) != 3, 1)
|
34
34
|
|
@@ -121,7 +121,7 @@
|
|
121
121
|
# [1, 1, 1, 0, 0, 0, 0, 0, 0],
|
122
122
|
# [0, 0, 0, 0, 1, 2, 3, 3, 3]], dtype=int8)
|
123
123
|
|
124
|
-
c1D = np.convolve(b1D, np.array([1, 1, 1]))[:-1].reshape(arr.shape)[:, 2:]
|
124
|
+
c1D = np.convolve(b1D, np.array([1, 1, 1]))[:-1].reshape(arr.shape)[:, 2:-1]
|
125
125
|
# array([[1, 2, 3, 2, 1, 0, 1, 1],
|
126
126
|
# [1, 0, 1, 2, 3, 2, 1, 0],
|
127
127
|
# [0, 0, 0, 1, 1, 1, 0, 0],
|