我知道这个问题已经存在,但答案对我没有帮助。
def function(T,theta,A):
x=(T-theta)/A
return(x)
filen=pd.read_csv('filename')
filelist=[file,file2,...,filen)
labels=['name1','name2',...]
colors=['red','blue','green',...]
for i in range(len(filelist)):
x=filelist[i]['column1']
y=filelist[i]['column2']
y2=(1/y)
plt.plot(x, y2, colors[i], label=labels[i])
plt.legend()
plt.plot()
w=np.where(x>170)
print(x[w]) #error, can only tuple index with multiindex
other_fit=curve_fit(function,x,y)
popt, pcov=other_fit
plt.plot(x, function(x, *popt), colors2[i], label=labels2[i])
plt.show()
错误发生在x[w]
当我不在for循环中时,没有错误。
错误消息如下:
ValueError: Can only tuple-index with a MultiIndex
答案 0 :(得分:1)
尝试改变:
w=np.where(x>170)
为:
w = x[x>170]
np.where
会在你的情况下返回一个元组:
返回
If only `condition` is given, return the tuple ``condition.nonzero()``, the indices where `condition` is True.