線性代數 向量長度
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
線性代數 向量長度