Vector with User Defined Length | Linear Algebra using Python

Linear Algebra using Python | Vector with User Defined Length: Here, we are going to learn how to define vector with user defined length in Python?
Submitted by Anuj Singh, on May 21, 2020

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.

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.

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]





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.