回答編集履歴
3
回答を修正
answer
CHANGED
@@ -1,19 +1,10 @@
|
|
1
|
+
行列`a`から、`b`のうち値が1である列位置を抽出した結果が`c`になります。
|
1
2
|
```Python
|
2
3
|
import numpy as np
|
3
|
-
|
4
|
+
a = np.array([[2,5,3,8],[1,4,2,7]])
|
4
|
-
print(l) # [0 1 0 1]
|
5
|
-
n = l[1::2] # 1番目から最後まで1つおきに取得 ※0=先頭
|
6
|
-
print(n) # [1 1]
|
7
|
-
```
|
8
|
-
|
9
|
-
あるいはこちらでしょうか?
|
10
|
-
行列`a`から、`b`のうち値が1である行位置を抽出した結果が`c`になります。
|
11
|
-
```Python
|
12
|
-
import numpy as np
|
13
|
-
a = np.arange(8).reshape(4,2)
|
14
5
|
print(a)
|
15
6
|
b = np.array([0,1,0,1])
|
16
7
|
print(b)
|
17
|
-
c = a[b==1
|
8
|
+
c = a[:,b==1]
|
18
9
|
print(c)
|
19
10
|
```
|
2
追記
answer
CHANGED
@@ -6,7 +6,8 @@
|
|
6
6
|
print(n) # [1 1]
|
7
7
|
```
|
8
8
|
|
9
|
-
あるいはこちらでしょうか?
|
9
|
+
あるいはこちらでしょうか?
|
10
|
+
行列`a`から、`b`のうち値が1である行位置を抽出した結果が`c`になります。
|
10
11
|
```Python
|
11
12
|
import numpy as np
|
12
13
|
a = np.arange(8).reshape(4,2)
|
1
回答を追記
answer
CHANGED
@@ -4,4 +4,15 @@
|
|
4
4
|
print(l) # [0 1 0 1]
|
5
5
|
n = l[1::2] # 1番目から最後まで1つおきに取得 ※0=先頭
|
6
6
|
print(n) # [1 1]
|
7
|
+
```
|
8
|
+
|
9
|
+
あるいはこちらでしょうか? 値が1である行を抽出します。
|
10
|
+
```Python
|
11
|
+
import numpy as np
|
12
|
+
a = np.arange(8).reshape(4,2)
|
13
|
+
print(a)
|
14
|
+
b = np.array([0,1,0,1])
|
15
|
+
print(b)
|
16
|
+
c = a[b==1,:]
|
17
|
+
print(c)
|
7
18
|
```
|