线性代数 向量长度
Prerequisite: Defining a vector
先决条件: 定义向量
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 in code itself. In this tutorial, we will just extend one step more to make a code in a way that users can define a vector.
线性代数是使用向量空间和矩阵的线性方程组的数学分支。 换句话说,向量是n维空间中只有一列的矩阵。 因此向量是线性代数的重要组成部分之一。 在以前的教程中,我们在代码本身中定义了向量。 在本教程中,我们将进一步扩展一步,以使用户可以定义矢量的方式编写代码。
Keypoint: For a code to generate a user-defined vector, we need one major parameter i.e. N. N represents the number of elements in a vector.
关键点:为了使代码生成用户定义的向量,我们需要一个主要参数,即N。 N表示向量中元素的数量。
Python代码定义用户定义长度的向量 (Python code to define a vector with user defined length)
# Vectors in Linear Algebra Sequnce
# Vector with User Defined Length
n = int(input("Enter the length of the vector you want to define: "))
v = []
for i in range(n):
v.append(int(input('Enter the element: ')))
print("Vector you defined = ", v)
Output:
输出:
RUN 1:
Enter the length of the vector you want to define: 5
Enter the element: 12
Enter the element: 23
Enter the element: 31
Enter the element: 22
Enter the element: 56
Vector you defined = [12, 23, 31, 22, 56]
RUN 2:
Enter the length of the vector you want to define: 6
Enter the element: 33
Enter the element: 123
Enter the element: 9
Enter the element: 10
Enter the element: 98
Enter the element: 13
Vector you defined = [33, 123, 9, 10, 98, 13]
翻译自: https://www.includehelp.com/python/vector-with-user-defined-length.aspx
线性代数 向量长度