回答編集履歴
2
numpy\.nan_to_num例を追加
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
`== np.nan`ではなく[numpy.isnan](https://docs.scipy.org/doc/numpy/reference/generated/numpy.isnan.html)で判定してください。
|
2
2
|
|
3
|
-
さらに[numpy.where](https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.where.html)を使えば一括置換できます。
|
3
|
+
さらに[numpy.where](https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.where.html)や[numpy.nan_to_num](https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.nan_to_num.html)を使えば一括置換できます。
|
4
4
|
|
5
5
|
```Python
|
6
6
|
|
@@ -17,6 +17,14 @@
|
|
17
17
|
G2 = np.where( np.isnan(G),0,G)
|
18
18
|
|
19
19
|
print(G2)
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
# numpy.nan_to_numで一括置換
|
24
|
+
|
25
|
+
G3 = np.nan_to_num(G)
|
26
|
+
|
27
|
+
print(G3)
|
20
28
|
|
21
29
|
|
22
30
|
|
1
numpy\.where例を追加
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
`== np.nan`ではなく[numpy.isnan](https://docs.scipy.org/doc/numpy/reference/generated/numpy.isnan.html)で判定してください。
|
2
2
|
|
3
|
-
|
3
|
+
さらに[numpy.where](https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.where.html)を使えば一括置換できます。
|
4
4
|
|
5
5
|
```Python
|
6
6
|
|
@@ -9,6 +9,16 @@
|
|
9
9
|
G = np.array([[1,2,np.nan],[4,np.nan,6]])
|
10
10
|
|
11
11
|
print(G)
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
# numpy.whereで一括置換
|
16
|
+
|
17
|
+
G2 = np.where( np.isnan(G),0,G)
|
18
|
+
|
19
|
+
print(G2)
|
20
|
+
|
21
|
+
|
12
22
|
|
13
23
|
for i in range(G.shape[0]):
|
14
24
|
|