【问题标题】:Why does numpy+mkl make it so my object is not iterable?为什么 numpy+mkl 使我的对象不可迭代?
【发布时间】:2017-08-25 07:10:28
【问题描述】:

此代码在安装 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+mkl-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

我太不合群了。任何帮助将不胜感激。

【问题讨论】:

    标签: windows python-2.7 numpy scipy


    【解决方案1】:

    你的列元组只有一个元素,所以你需要一个尾随逗号,否则它不会被解释为可迭代:

    numpy.loadtxt(file, skiprows=1, usecols=(1,)))

    在 numpy 1.11 中,usecols 的整数值是不允许的,这与最新版本不同。安装 whl 时,您可能会降低版本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-22
      • 2021-03-01
      • 2021-05-16
      • 1970-01-01
      • 1970-01-01
      • 2020-04-09
      • 2018-05-18
      相关资源
      最近更新 更多