Numpy 简明教程
NumPy - Environment
标准 Python 发行版没有捆绑 NumPy 模块。一个轻量级的替代方法是使用流行的 Python 包安装程序 pip 安装 NumPy。
Standard Python distribution doesn’t come bundled with NumPy module. A lightweight alternative is to install NumPy using popular Python package installer, pip.
pip install numpy
启用 NumPy 的最佳途径是使用专门针对您的操作系统的可安装二进制包。这些二进制文件包含完整的 SciPy 堆栈(包括 NumPy、SciPy、matplotlib、IPython、SymPy 和 nose 包以及核心 Python)。
The best way to enable NumPy is to use an installable binary package specific to your operating system. These binaries contain full SciPy stack (inclusive of NumPy, SciPy, matplotlib, IPython, SymPy and nose packages along with core Python).
Windows
Anaconda(来自 https://www.continuum.io )是 SciPy 堆栈的免费 Python 分发版。它还可用于 Linux 和 Mac。
Anaconda (from https://www.continuum.io) is a free Python distribution for SciPy stack. It is also available for Linux and Mac.
Canopy ( https://www.enthought.com/products/canopy/ )可作为针对 Windows、Linux 和 Mac 的 SciPy 堆栈的免费以及商业版分发。
Canopy (https://www.enthought.com/products/canopy/) is available as free as well as commercial distribution with full SciPy stack for Windows, Linux and Mac.
Python (x,y):它是一个针对 Windows 操作系统的、拥有 SciPy 堆栈和 Spyder IDE 的免费 Python 分发版。(可从 https://www.python-xy.github.io/ 下载)
Python (x,y): It is a free Python distribution with SciPy stack and Spyder IDE for Windows OS. (Downloadable from https://www.python-xy.github.io/)
Linux
各个 Linux 发行版的包管理器用于安装 SciPy 堆栈中的一个或多个包。
Package managers of respective Linux distributions are used to install one or more packages in SciPy stack.
For Ubuntu
sudo apt-get install python-numpy
python-scipy python-matplotlibipythonipythonnotebook python-pandas
python-sympy python-nose
For Fedora
sudo yum install numpyscipy python-matplotlibipython
python-pandas sympy python-nose atlas-devel
Building from Source
必须安装带有 distutils 的核心 Python(2.6.x、2.7.x 和 3.2.x 及更高版本),并且应启用 zlib 模块。
Core Python (2.6.x, 2.7.x and 3.2.x onwards) must be installed with distutils and zlib module should be enabled.
必须有 GNU gcc(4.2 及更高版本)C 编译器。
GNU gcc (4.2 and above) C compiler must be available.
要安装 NumPy,请运行以下命令。
To install NumPy, run the following command.
Python setup.py install
要测试 NumPy 模块是否已正确安装,请尝试从 Python 提示符对其进行导入。
To test whether NumPy module is properly installed, try to import it from Python prompt.
import numpy
如果未安装,将显示以下错误消息。
If it is not installed, the following error message will be displayed.
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import numpy
ImportError: No module named 'numpy'
或者,可以使用以下语法导入 NumPy 包
Alternatively, NumPy package is imported using the following syntax −
import numpy as np