回答編集履歴

3

回答を修正

2017/06/13 08:51

投稿

can110
can110

スコア38266

test CHANGED
@@ -1,28 +1,10 @@
1
- ```Python
2
-
3
- import numpy as np
4
-
5
- l = np.array([0,1,0,1])
6
-
7
- print(l) # [0 1 0 1]
8
-
9
- n = l[1::2] # 1番目から最後まで1つおきに取得 ※0=先頭
10
-
11
- print(n) # [1 1]
12
-
13
- ```
14
-
15
-
16
-
17
- あるいはこちらでしょうか?
18
-
19
- 行列`a`から、`b`のうち値が1である位置を抽出した結果が`c`になります。
1
+ 行列`a`から、`b`のうち値が1である位置を抽出した結果が`c`になります。
20
2
 
21
3
  ```Python
22
4
 
23
5
  import numpy as np
24
6
 
25
- a = np.arange(8).reshape(4,2)
7
+ a = np.array([[2,5,3,8],[1,4,2,7]])
26
8
 
27
9
  print(a)
28
10
 
@@ -30,7 +12,7 @@
30
12
 
31
13
  print(b)
32
14
 
33
- c = a[b==1,:]
15
+ c = a[:,b==1]
34
16
 
35
17
  print(c)
36
18
 

2

追記

2017/06/13 08:51

投稿

can110
can110

スコア38266

test CHANGED
@@ -14,7 +14,9 @@
14
14
 
15
15
 
16
16
 
17
- あるいはこちらでしょうか? 値が1である行を抽出します。
17
+ あるいはこちらでしょうか?
18
+
19
+ 行列`a`から、`b`のうち値が1である行位置を抽出した結果が`c`になります。
18
20
 
19
21
  ```Python
20
22
 

1

回答を追記

2017/06/13 08:46

投稿

can110
can110

スコア38266

test CHANGED
@@ -11,3 +11,25 @@
11
11
  print(n) # [1 1]
12
12
 
13
13
  ```
14
+
15
+
16
+
17
+ あるいはこちらでしょうか? 値が1である行を抽出します。
18
+
19
+ ```Python
20
+
21
+ import numpy as np
22
+
23
+ a = np.arange(8).reshape(4,2)
24
+
25
+ print(a)
26
+
27
+ b = np.array([0,1,0,1])
28
+
29
+ print(b)
30
+
31
+ c = a[b==1,:]
32
+
33
+ print(c)
34
+
35
+ ```