Python Data Science 简明教程

Python Data Science - NumPy

What is NumPy?

NumPy 是一个 Python 软件包,代表“Numerical Python”。它是一個库,包含多维数组对象和一个用于处理数组的例程集合。

NumPy is a Python package which stands for 'Numerical Python'. It is a library consisting of multidimensional array objects and a collection of routines for processing of array.

Operations using NumPy

使用 NumPy,开发人员可以执行以下操作 −

Using NumPy, a developer can perform the following operations −

  1. Mathematical and logical operations on arrays.

  2. Fourier transforms and routines for shape manipulation.

  3. Operations related to linear algebra. NumPy has in-built functions for linear algebra and random number generation.

NumPy – A Replacement for MatLab

NumPy 通常与 SciPy (科学 Python)和 Mat−plotlib (绘图库)等软件包一起使用。这种组合广泛用作 MatLab 的替代品,后者是技术计算的流行平台。但是,Python 替代版 MatLab 现在被视为一种更现代、更完整的编程语言。

NumPy is often used along with packages like SciPy (Scientific Python) and Mat−plotlib (plotting library). This combination is widely used as a replacement for MatLab, a popular platform for technical computing. However, Python alternative to MatLab is now seen as a more modern and complete programming language.

它是开源的,这是 NumPy 的一个额外优势。

It is open source, which is an added advantage of NumPy.

ndarray Object

NumPy 中定义的最重要的对象是一个称为 ndarray 的 N 维数组类型。它描述了同种类型的项目集合。可以使用基于零的索引访问集合中的项目。ndarray 中的每个项目占用内存中相同大小的块。ndarray 中的每个元素都是数据类型对象的对象(称为 dtype )。从 ndarray 对象(通过切片)中提取的任何项目都由数组标量类型之一的 Python 对象表示。

The most important object defined in NumPy is an N-dimensional array type called ndarray. It describes the collection of items of the same type. Items in the collection can be accessed using a zero-based index. Every item in an ndarray takes the same size of block in the memory. Each element in ndarray is an object of data-type object (called dtype). Any item extracted from ndarray object (by slicing) is represented by a Python object of one of array scalar types.

在下一章中,我们将看到有关在数据科学工作中使用 NumPy Python 库的许多示例。

We will see lots of examples on using NumPy library of python in Data science work in the next chapters.