包不工作,使用 Anaconda

Packages not working, using Anaconda

我已经为 Windows 安装了 Anaconda。它在我的工作电脑上,所以我选择了 "Just for Me" 选项,因为我没有管理员权限。

Anaconda 安装在以下目录中:

c:\Users\huf069\AppData\Local\Continuum\Anaconda

Windows 安装程序已将此目录(+ Anaconda\Scripts 目录)添加到系统路径。

我可以启动 Python 但正在尝试 运行 x = randn(100,100) 给我一个 Name Error: name 'randn' is not defined, 然而,据我所知,这个命令在使用 Anaconda 时应该有效,因为包含了 numpy 包。

如果我这样做,效果很好:

import numpy
numpy.random.randn(100,100)

有人知道会发生什么吗?

I can launch Python, but trying to run x = randn(100,100) gives me a Name Error: name 'randn' is not defined, whereas, as I understood, this command should work when using Anaconda, as the numpy package is included

Anaconda 发行版附带了 numpy 软件包,但您仍然需要 import 该软件包。如果你想使用randn()函数而不必调用完整的名称,你可以将它导入到你的本地命名空间:

from numpy.random import randn
x = randn(100,100)

否则,调用 numpy.random.randn 是你的方法。

您可能想看看 Python 教程的 Modules section