質問編集履歴
4
コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -36,7 +36,7 @@
|
|
36
36
|
|
37
37
|
for i in range(0,2):
|
38
38
|
|
39
|
-
A1 = dL[i] + Ds2.loc[:, Ds2.columns.str.contains(r'(?=.*W)(?=.*%s)' % i)].values + Ds1.loc[:, Ds1.columns.str.contains(r'(?=.*W)(?=.*%s)' % i)].values
|
39
|
+
A1 = dL[i] + Ds2.loc[:, Ds2.columns.str.contains(r'(?=.*W)(?=.*%s)' % i)].values + Ds1.loc[:, Ds1.columns.str.contains(r'(?=.*W)(?=.*%s)' % i)].values
|
40
40
|
|
41
41
|
B = np.r_[B, A1.reshape(1, -1)]
|
42
42
|
|
3
無駄削除
test
CHANGED
File without changes
|
test
CHANGED
@@ -70,7 +70,7 @@
|
|
70
70
|
|
71
71
|
|
72
72
|
|
73
|
-
C:\
|
73
|
+
C:\lib\site-packages\numpy\lib\index_tricks.py in __getitem__(self, key)
|
74
74
|
|
75
75
|
336 objs[k] = objs[k].astype(final_dtype)
|
76
76
|
|
2
エラーなどの足りない情報の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -15,6 +15,12 @@
|
|
15
15
|
Ds1 = pd.read_excel('sample.xlsx', '--')
|
16
16
|
|
17
17
|
Ds2 = pd.read_excel('sample.xlsx', '-')
|
18
|
+
|
19
|
+
# データ名(実際はすでにエクセルに下記のデータ名が入力されている)
|
20
|
+
|
21
|
+
L5 = ['W-A0', 'W-B0', 'W-F0', 'W-C1', 'W-E1', 'W-A2', 'W-B2', 'W-D2', 'W-F2', 'W-C3', 'W-E3',
|
22
|
+
|
23
|
+
'W-A4', 'W-B4', 'W-F4']
|
18
24
|
|
19
25
|
|
20
26
|
|
@@ -38,7 +44,53 @@
|
|
38
44
|
|
39
45
|
```
|
40
46
|
|
47
|
+
Ds1,2ともにshapeは(164,14)の数値列,数値はランダムです.
|
48
|
+
|
49
|
+
また両方ともcolumnsは上記コード内のリストL5です.
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
発生エラー
|
54
|
+
|
55
|
+
```
|
56
|
+
|
57
|
+
---------------------------------------------------------------------------
|
58
|
+
|
59
|
+
ValueError Traceback (most recent call last)
|
60
|
+
|
61
|
+
<ipython-input-28-2163de09022c> in <module>()
|
62
|
+
|
63
|
+
16 for i in range(0,2):
|
64
|
+
|
65
|
+
17 A1 = dL[i] + Ds2.loc[:, Ds2.columns.str.contains(r'(?=.*W)(?=.*%s)' % i)].values + Ds1.loc[:, Ds1.columns.str.contains(r'(?=.*W)(?=.*%s)' % i)].values
|
66
|
+
|
67
|
+
---> 18 B = np.r_[B, A1.reshape(1, -1)]
|
68
|
+
|
69
|
+
19 B.T
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
C:\Users\Ohgak\Anaconda3\lib\site-packages\numpy\lib\index_tricks.py in __getitem__(self, key)
|
74
|
+
|
75
|
+
336 objs[k] = objs[k].astype(final_dtype)
|
76
|
+
|
77
|
+
337
|
78
|
+
|
79
|
+
--> 338 res = _nx.concatenate(tuple(objs), axis=self.axis)
|
80
|
+
|
81
|
+
339 return self._retval(res)
|
82
|
+
|
83
|
+
340
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
ValueError: all the input array dimensions except for the concatenation axis must match exactly
|
88
|
+
|
89
|
+
```
|
90
|
+
|
41
91
|
for文のA1までは動くのですが,Bのところでエラーが発生します.改善できないでしょうか.
|
92
|
+
|
93
|
+
|
42
94
|
|
43
95
|
|
44
96
|
|
1
コードの変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
for文で複数の配列とリストの繰り返し計算したいのですが,うまくいかないです.
|
2
|
-
|
3
|
-
やりたいことは,リストと複数の配列を計算して,計算結果の配列を追加していきたいです.
|
1
|
+
**やりたいことは,リストと複数の配列を計算して,計算結果の配列を空の配列に追加していきたいです.**
|
4
2
|
|
5
3
|
|
6
4
|
|
@@ -12,11 +10,53 @@
|
|
12
10
|
|
13
11
|
|
14
12
|
|
13
|
+
# データ読み込み
|
14
|
+
|
15
|
+
Ds1 = pd.read_excel('sample.xlsx', '--')
|
16
|
+
|
17
|
+
Ds2 = pd.read_excel('sample.xlsx', '-')
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
# リスト
|
22
|
+
|
23
|
+
dL = list(range(100, 2100, 200))
|
24
|
+
|
25
|
+
B = np.zeros((0, Ds1.values.shape[0]))
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
# 計算
|
30
|
+
|
31
|
+
for i in range(0,2):
|
32
|
+
|
33
|
+
A1 = dL[i] + Ds2.loc[:, Ds2.columns.str.contains(r'(?=.*W)(?=.*%s)' % i)].values + Ds1.loc[:, Ds1.columns.str.contains(r'(?=.*W)(?=.*%s)' % i)].values*
|
34
|
+
|
35
|
+
B = np.r_[B, A1.reshape(1, -1)]
|
36
|
+
|
37
|
+
B.T
|
38
|
+
|
39
|
+
```
|
40
|
+
|
41
|
+
for文のA1までは動くのですが,Bのところでエラーが発生します.改善できないでしょうか.
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
以下のコードではうまくいくのですが,上記ではなぜできないのか原因がわかりません.
|
46
|
+
|
47
|
+
```python
|
48
|
+
|
49
|
+
import pandas as pd
|
50
|
+
|
51
|
+
import numpy as np
|
52
|
+
|
53
|
+
|
54
|
+
|
15
55
|
# データ
|
16
56
|
|
17
|
-
Ds1 = pd.DataFrame(np.random.randn(10,
|
57
|
+
Ds1 = pd.DataFrame(np.random.randn(10, 2), columns=['L-0','L-1'])
|
18
58
|
|
19
|
-
Ds2 = pd.DataFrame(np.arange(30).reshape(10, 2)
|
59
|
+
Ds2 = pd.DataFrame(np.arange(30).reshape(10, 3), columns=['L-0','L-1','L-2'])
|
20
60
|
|
21
61
|
|
22
62
|
|
@@ -24,7 +64,7 @@
|
|
24
64
|
|
25
65
|
dL1 = [100, 300, 450, 600, 750, 900]
|
26
66
|
|
27
|
-
B = np.zeros((0, 10))
|
67
|
+
B = np.zeros((0, Ds1.values.shape[0]))
|
28
68
|
|
29
69
|
|
30
70
|
|
@@ -32,20 +72,12 @@
|
|
32
72
|
|
33
73
|
for i in range(0,2):
|
34
74
|
|
35
|
-
A1 = dL[i] + Ds2.loc[:,i].values
|
75
|
+
A1 = dL[i] + Ds2.loc[:, Ds2.columns.str.contains(r'(?=.*%s)' % i)].values + Ds1.loc[:, Ds1.columns.str.contains(r'(?=.*%s)' % i)].values
|
36
76
|
|
37
77
|
B = np.r_[B, A1.reshape(1, -1)]
|
38
78
|
|
39
|
-
|
79
|
+
|
40
80
|
|
41
81
|
B.T
|
42
82
|
|
43
83
|
```
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
Ds1とDs2で配列サイズが異なることが原因ですが,なんとかならないでしょうか.また,他の方法で簡単にできる方法があれば教えていただければ幸いです.
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
以上,よろしくお願いいたします.
|