我有一个吸收值的矩阵,我从整个谱图中提取出来。我称之为矩阵“specdt”如何使用numpy对行数组执行操作?
每行代表特定波长下多个样本的值。我想找到称为“浓度”的单独浓度值的回归r^2值。
这是我到目前为止有:
regression = []
for row in specdt:
x = Concentration
y = specdt[row,:]
slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
regression.append(r_value**2)
regression_n = numpy.asarray(regression)
numpy.savetxt("r2_2.csv", regression_n, delimiter=",")
我得到的错误:
Traceback (most recent call last):
file "blah blah", line 42, in <module>
y = specdt[row,:]
InexError: arrays used as indices must be of integer (or boolean) type
我怀疑这是因为“行”不是一个整数,所以我试图遍历一个“t”变量;没有运气。
我怀疑这是我试图拉行到lin值的y值的方式,但我似乎无法找到另一种方式来做到这一点。
任何意见非常感谢!
编辑:我应该指出,
y = row
是我想的第一件事。
它给了我下面的错误:
Traceback (most recent call last):
File "C:\Users\ME\Downloads\Personal\Spectrometer\test\Spectrum3.py", line 42, in <module>
slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
File "C:\Python27\lib\site-packages\scipy\stats\_stats_mstats_common.py", line 92, in linregress
ssxm, ssxym, ssyxm, ssym = np.cov(x, y, bias=1).flat
File "C:\Python27\lib\site-packages\numpy\lib\function_base.py", line 2432, in cov
X = np.vstack((X, y))
File "C:\Python27\lib\site-packages\numpy\core\shape_base.py", line 230, in vstack
return _nx.concatenate([atleast_2d(_m) for _m in tup], 0)
ValueError: all the input array dimensions except for the concatenation axis must match exactly
的conncentration阵列的尺寸和行应该是相同的。
linregress精美的作品,如果我拉出一列(我换位specdt)。这是工作的代码,如果这能帮助:
##take only column 26 or the values for 2268; print stuff
#Absorbance2268 = spectral_data[:, 25]
#print(Absorbance2268.shape)
#print(Absorbance2268)
#
##manual entry of concentration values + array info
#conc =[0,0,0,0,0,6,6,6,6,6,6,6,6,6,6,8,8,8,8,8,10,10,10,10,10,4,4,4,4,4]
#Concentration = numpy.asarray(conc)
#
#print(Concentration.shape)
#print(Concentration)
#
##performing linear regression.
#x = Concentration
#y = Absorbance2268
#
#slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
#
#print "r-squared:", r_value**2
'谱(s?)'谱是谱的复数 – dawg
哈哈谢谢。 Part 1 of 2:P – FLAV10
假设'specdt'是一个numpy数组或矩阵,那么'row'已经是你想要的行(不是行的索引),所以'y = specdt [row,:]'应该简单地'Y = row'。 –