0% found this document useful (0 votes)
9 views3 pages

Advanced Technology Lab 4

The document provides two programs: one for creating and printing a matrix based on user input for rows and columns, and another for creating horizontal and vertical vectors using the numpy library. The matrix program collects integer entries row-wise and displays them, while the vector program demonstrates the creation of both row and column vectors. Sample outputs for both programs are included to illustrate their functionality.

Uploaded by

g.dejasvini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Advanced Technology Lab 4

The document provides two programs: one for creating and printing a matrix based on user input for rows and columns, and another for creating horizontal and vertical vectors using the numpy library. The matrix program collects integer entries row-wise and displays them, while the vector program demonstrates the creation of both row and column vectors. Sample outputs for both programs are included to illustrate their functionality.

Uploaded by

g.dejasvini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Programs using Matrix.

PROGRAM:
R = int(input("Enter the number of rows:"))
C = int(input("Enter the number of columns:"))

# Initialize matrix
matrix = []
print("Enter the entries rowwise:")

# For user input


for i in range(R): # A for loop for row entries
a =[]
for j in range(C): # A for loop for column entries
a.append(int(input()))
matrix.append(a)

# For printing the matrix


for i in range(R):
for j in range(C):
print(matrix[i][j], end = " ")
print()
OUTPUT:
Enter the number of rows:2
Enter the number of columns:3
Enter the entries rowwise:
1
2
3
4
1
2
123
412

Programs using Vector


PROGRAM:
# importing numpy
import numpy as np

# creating a 1-D list (Horizontal)


list1 = [1, 2, 3]

# creating a 1-D list (Vertical)


list2 = [[10],
[20],
[30]]

# creating a vector1
# vector as row
vector1 = np.array(list1)

# creating a vector 2
# vector as column
vector2 = np.array(list2)

# showing horizontal vector


print("Horizontal Vector")
print(vector1)
print("----------------")

# showing vertical vector


print("Vertical Vector")
print(vector2)

OUTPUT:
Horizontal Vector
[1 2 3]
----------------
Vertical Vector
[[10]
[20]
[30]]

You might also like