使用Numpy定义向量| 使用Python的线性代数

Linear algebra is the branch of mathematics concerning linear equations by using vector spaces and through matrices. In other words, a vector is a matrix in n-dimensional space with only one column. So vector is one of the important constituents for linear algebra. In previous tutorials, we defined the vector using the list. Defining a vector using a list is very fine and easy but it has some limitations. We can only define vectors through lists when there is only vector manipulation involved. As matrices are involved, then we have to define a vector using A supremely-optimized, well-maintained scientific computing package for Python called numpy.

线性代数是使用向量空间和矩阵的线性方程组的数学分支。 换句话说,向量是n维空间中只有一列的矩阵。 因此向量是线性代数的重要组成部分之一。 在以前的教程中,我们使用列表定义了向量。 使用列表定义向量非常好且容易,但是有一些限制。 当仅涉及向量操作时,我们只能通过列表定义向量。 由于涉及到矩阵,因此我们必须使用一个经过优化的,维护良好的Python科学计算软件包numpy来定义向量。

Let's see how we can define a vector using this library:

让我们看看如何使用该库定义向量:

使用Numpy定义矢量的Python代码 (Python code for Defining Vector using Numpy)

# Linear Algebra Learning Sequence
# Defining a vector using numpy

import numpy as np

# Use of np.array() to define a vector
V1 = np.array([[1],[2],[3]])
V2 = np.array([[14],[23],[35],[56],[754],[123]])

# printing vectors
print("The Vector V1 = ",V1)
print("The Vector V2 = ",V2)

Output:

输出:

The Vector V1 =  [[1]
 [2]
 [3]]
The Vector V2 =  [[ 14]
 [ 23]
 [ 35]
 [ 56]
 [754]
 [123]]


翻译自: https://www.includehelp.com/python/defining-vector-using-numpy.aspx

你可能感兴趣的:(列表,python,机器学习,numpy,线性代数)