Python Numpy - 模块没有“排列”属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32238886/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 11:16:19  来源:igfitidea点击:

Numpy - module has no attribute 'arrange'

pythonnumpy

提问by Joey Orlando

Seems like an incredibly basic error, I've tried uninstalling and reinstalling the latest version of Numpy (1.9) and that didn't seem to solve my issue. I am getting the following error when trying to use the arrange function:

似乎是一个令人难以置信的基本错误,我尝试卸载并重新安装最新版本的 Numpy (1.9),但这似乎并没有解决我的问题。尝试使用排列功能时出现以下错误:

Traceback (most recent call last):
  File "names.py", line 37, in <module>
    top1000.index = np.arrange(len(top1000))
AttributeError: 'module' object has no attribute 'arrange'

Printing the version confirms that it is indeed 1.9. I've not been able to come across anyone else reporting this specific issue. I've also tried this on two separate Macs and still get the same exact error.

打印版本确认它确实是1.9。我没能遇到任何其他人报告这个特定问题。我也在两台单独的 Mac 上尝试过这个,但仍然得到完全相同的错误。

import numpy as np
import pandas as pd

print np.__version__

grouped = names.groupby(['year', 'sex'])
top1000 = grouped.apply(get_top1000)
top1000.index = np.arrange(len(top1000))

回答by DaveQ

You should try numpy.arange()instead, if that is what you meant?

你应该试试numpy.arange(),如果这就是你的意思?