numpy矩阵运算加速原理
Over the course of this article, we shall learn the various features and functions of the Python library, NumPy
在本文的整个过程中,我们将学习Python库NumPy的各种特性和功能。
NumPy is one of the Python libraries, that supports multi-dimensional, substantial arrays as well as matrices. It also supports a large collection of mathematical functions to operate on these arrays. NumPy provides a strong base for many other data science and data visualization libraries.
NumPy是Python库之一,它支持多维的,实质性的数组以及矩阵。 它还支持在这些数组上运行的大量数学函数。 NumPy为许多其他数据科学和数据可视化库提供了坚实的基础。
In this article we will create, index and manipulate arrays using NumPy. (You will need to have prior knowledge on how tuples and lists work in Python.)
在本文中,我们将使用NumPy创建,索引和操作数组。 (您将需要具有有关元组和列表在Python中如何工作的先验知识。)
First, we’ll look at NumPy arrays. A NumPy array consists of values that can be indexed with slices, but also with boolean or integer arrays (masks). The shape of an array denotes the size of an array along each dimension and it is expressed using a tuple of integers as well. For a standard 2D array, the shape gives the number of rows followed by the number of columns.
首先,我们来看一下NumPy数组。 NumPy数组由可以用切片索引的值组成,但也可以用布尔或整数数组(掩码)索引。 数组的形状表示数组在每个维度上的大小,它也使用整数元组表示。 对于标准2D数组,形状将给出行数,然后是列数。
Before we start, make sure you have all the necessary libraries installed in your system.
在开始之前,请确保您已在系统中安装了所有必需的库。
Using conda:
使用conda:
conda install numpy
Using pip:
使用点子:
pip install numpy
使用NumPy创建数组(Creating arrays using NumPy)
>>> import numpy as np
>>> a = np.array([1,22,333])
>>> print(a)
[1 22 333]
Let’s play around with arrays a little before we get into mor