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
[Link](int(input()))
[Link](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 = [Link](list1)
# creating a vector 2
# vector as column
vector2 = [Link](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]]