【发布时间】:2018-06-12 17:09:47
【问题描述】:
test = np.array([20, 21, 22, 23, 22, 21])
test = test.astype(float)
result = np.zeros((1,1))
for i in range(len(test)-3):
d = np.abs(test[i+3]-test[i])
#print(d)
v = 0
for j in range(3):
v = v + np.asscalar(
np.abs(test[i+3-j] - test[i+3-(j+1)]))
out = d / v
result = np.hstack((result, out))
我希望这段代码的结果是这样的 numpy 数组的形状 -> (3,1) 正常输出原本应该如下所示:[1, 0.333, 0.333] 然而,当我运行这段代码时,我得到了一个类似标题的错误。
【问题讨论】:
-
你不能在用
result=np.append(result, out)声明result =[]后追加到一个数组吗?不过,这将附加到位。