Cannot subtract two columns after one was interpolated to fit the other.

时间:2018-11-27 00:52:11

标签: python matplotlib

I am trying to perform a chi squared test with an interpolated column, but I keep getting the return of 'operands could not be broadcast together with shapes (314,) (700,)'. I am not sure how to correct this, as I need to subtract from the interpolated values.

x = spectra4[474:1174,0]
y = spectra4[474:1174,1]
x_new = Mystery[2:316,0]
y_new = np.interp(Mystery[2:316,0], 
spectra4[474:1174,0],spectra4[474:1174,1] )
plt.plot(x, y, '-')
plt.plot(x_new, y_new, '-')
plt.legend(['linear spectra4', 'linear Mystery'], loc='best')
plt.xlim(3500,7000)
plt.show()
plt.savefig('Mysteryinterp.png')

totsub = y_new - y 
numerator = totsub**2
total = total = numerator/y
chi2 = total.sum()
print(chi2)

1 个答案:

答案 0 :(得分:0)

The problem is with this line totsub = y_new - y

y_new is a 314 element matrix and y is a 700 element matrix. Matrix dimensions need to match to do matrix subtraction.