我将循环结果保存在数组中,但收到错误:
all the input array dimensions except for the concatenation axis must match exactly
代码是:
r = 24
sp = np.zeros(r)
p = np.zeros(r)
for t in range(r):
sp[t], p[t] = scipy.stats.spearmanr((df1['Pasto_1'][t:]), (df1['HumedadPasto_1'][:-t]))
我希望输出保存在 s
和 p
中。如果您知道我做错了什么,非常感谢!
最佳答案
问题很可能出现在第一次迭代中:当 t
为 0 时,df1['Pasto_1'][t:]
是完整系列,但 >df1['HumedadPasto_1'][:-t]
为空。您可以简单地将 0 视为特殊情况并做好:
for t in range(r):
s1 = df1['Pasto_1'][t:]
s2 = df1['HumedadPasto_1'][:-t] if t > 0 else df1['HumedadPasto_1']
sp[t], p[t] = scipy.stats.spearmanr(s1, s2)
关于python - 如何修复: "All the input array dimensions except for the concatenation axis must match exactly" python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58254041/