此代码用于在安装scipy之前“收集”我的所有文本数据:
#load a list with the filenames in root folder with .Spectrum extensions, stripping only the absorbance values
Spectral_Output = []
for file in glob.glob("*.Spectrum"):
Spectral_Output.append(
numpy.loadtxt(file, skiprows=1, usecols=(1)))
#convert to a numpy array and print dimensions
spectral_data = numpy.asarray(Spectral_Output)
print(spectral_data.shape)
#take only column 26 or the values for 2268; print stuff
Absorbance2268 = spectral_data[:, 25]
然后我想在另一个浓度阵列上运行回归stats.linregress(x,y),所以我安装了Scipy。
出于某种原因pip不会在Windows上使用scipy,所以我安装了 numpy的-1.11.3 + MRL-cp27-cp27m-win32.whl 和 SciPy的-0.19.0-cp27-cp27m-win32.whl 从这里:http://www.lfd.uci.edu/~gohlke/pythonlibs/按照scipy网站的推荐
现在,代码抛出了这个错误:
Traceback (most recent call last):
File "C:\Spectrometer\Spectrometer\0330\Spectrum.py", line 31, in <module>
numpy.loadtxt(file, skiprows=1, usecols=(1)))
File "C:\Python27\lib\site-packages\numpy\lib\npyio.py", line 790, in loadtxt
usecols = list(usecols)
TypeError: 'int' object is not iterable
我离开了联盟。任何帮助将不胜感激。
答案 0 :(得分:3)
你的列元组只有一个元素,所以你需要一个尾随的逗号,否则它不会被解释为可迭代的:
numpy.loadtxt(file, skiprows=1, usecols=(1,)))
在numpy 1.11中,与最新版本不同,不允许usecols
的整数值。安装whl时,您可能会下载版本。