[英]Numpy: create an array of arrays using vstack
我想使用vstack創建一個數組的numpy數組,但是我收到此錯誤消息: all the input array dimensions except for the concatenation axis must match exactly
到目前為止我嘗試過的是:
all_exp = np.array([])
for idx, rw in df_gamma_count.iterrows():
exp = rw['Pr_A_perc'] * ( rw['gamma_index'] * float(row['spread_perc']) * (1+f) - (f+f) )
gamma_and_exp = [exp, rw['gamma_index']]
all_exp = np.vstack((all_exp,gamma_and_exp))
知道為什么嗎? 謝謝!
為了使numpy.vstack()
正常工作,所有2D數組中的列數均應匹配。 例如:
In [14]: arr1 = np.arange(2*4).reshape(2, 4)
In [15]: arr2 = np.arange(5*4).reshape(5, 4)
In [16]: np.vstack((arr1, arr2))
Out[16]:
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11],
[12, 13, 14, 15],
[16, 17, 18, 19]])
錯誤訊息
除串聯軸外,所有輸入數組的尺寸必須完全匹配
表示在此示例中,我們沿軸0堆疊。因此,除軸0外的所有尺寸都應匹配。
例如,在形狀
(2, 4)
(5, 4)
^ ^
| |
| dimension of this axis should match.
dimensions along this axis can be different since we'are concatenating along axis 0.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.