Python3:ValueError:使用序列设置数组元素

2024-10-03 19:21:36 发布

您现在位置:Python中文网/ 问答频道 /正文

# Building tensor
V_High  = np.array( [np.ones(N)] )
V_Low   = np.array( [np.ones(N)] )
V_Close = np.array( [np.ones(N)] )
for i in range(M-1):
    V_High = np.vstack( (V_High, (Database[i][t+Starting_index-N:t+Starting_index,1])) ) 
    V_Low = np.vstack( (V_Low, (Database[i][t+Starting_index-N:t+Starting_index,2])) )
    V_Close = np.vstack( (V_Close, (Database[i][t+Starting_index-N:t+Starting_index,3])) )
x_t = np.stack( ( V_High, V_Low, V_Close), axis = 2 )
x_t = x_t.reshape(1, M, N, Feature)
# Building price fluctuation vector of yesterday
y_yesterday = [1]
for i in range(M-1):
    y_yesterday.append( int(Database[i][Starting_index+t-1][3])/int(Database[i][Starting_index+t-1][0]) )
y_yesterday = np.array(y_yesterday)
# Building a stack of price fluctuation vectors(2NN)
history = []
for forward in range(2*NN):
    y_history = [1]
    for i in range(M-1):
        y_history.append( int(Database[i][Starting_index+t+forward-2*NN][3])/(Database[i][Starting_index+t+forward-2*NN][0]) )
    y_history = np.array(y_history)
    history.append(y_history)
history = np.array(history)
history = np.transpose(history)

w_rlos = agent_rlos.predict(history)
w_rlosrl = agent_rlosrl.predict(x_t, w_rlos)

# Calculate Price fluctuation Vector yt:= v_t ./ v_t-1
y_t = [1]
for i in range(M-1):
    y_t.append( int(Database[i][Starting_index+t][3])/int(Database[i][Starting_index+t][0]) )
y_t = np.array(y_t)

# Calculate total money after the t_th trading period for each agent
p_end_t_rlosrl = p_start_t_rlosrl*np.dot(y_t, w_rlosrl)

这些是代码,当我运行它时,它总是显示:

文件“c:\Users\test\u history.py”,第144行,在Back\u test中

p_end_t_rlosrl = p_start_t_rlosrl*np.dot(y_t, w_rlosrl)

文件“<数组_函数内部>;“,第6行,以点为单位

ValueError:使用序列设置数组元素

我应该如何解决这个问题


Tags: inforcloseindexnprangearrayhistory