我知道这个错误信息(ValueError: too many values to unpack (expected 4)
)出现多个变量设置为值比函数返回时。`ValueError:太多的值来解压缩(预期4)`与`scipy.stats.linregress``
scipy.stats.linregress
根据scipy文档返回5个值(http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.linregress.html)。
这里是一个工作电话的短,重复的例子,然后呼叫失败,到linregress
:
什么可以解释的区别,为什么是第二个叫不好?
from scipy import stats
import numpy as np
if __name__ == '__main__':
x = np.random.random(10)
y = np.random.random(10)
print(x,y)
slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
'''
Code above works
Code below fails
'''
X = np.asarray([[-15.93675813],
[-29.15297922],
[ 36.18954863],
[ 37.49218733],
[-48.05882945],
[ -8.94145794],
[ 15.30779289],
[-34.70626581],
[ 1.38915437],
[-44.38375985],
[ 7.01350208],
[ 22.76274892]])
Y = np.asarray([[ 2.13431051],
[ 1.17325668],
[ 34.35910918],
[ 36.83795516],
[ 2.80896507],
[ 2.12107248],
[ 14.71026831],
[ 2.61418439],
[ 3.74017167],
[ 3.73169131],
[ 7.62765885],
[ 22.7524283 ]])
print(X,Y) # The array initialization succeeds, if both arrays are print out
for i in range(1,len(X)):
slope, intercept, r_value, p_value, std_err = (stats.linregress(X[0:i,:], y = Y[0:i,:]))
你能发布完整的错误信息和堆栈跟踪吗? – njzk2
你的X和Y的形状是:(12,1),但你需要的是(12,)。 – Dataman
也是''i'的值导致这个问题? – njzk2