0% found this document useful (0 votes)
3 views2 pages

Py 19

The document contains a practical exercise involving matrix operations using Python's NumPy and Matplotlib libraries. It demonstrates creating two matrices, performing addition, element-wise multiplication, and dot product, as well as calculating the transpose and determinant of a square matrix. Additionally, it includes plotting a line graph of the function y = 2x.

Uploaded by

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

Py 19

The document contains a practical exercise involving matrix operations using Python's NumPy and Matplotlib libraries. It demonstrates creating two matrices, performing addition, element-wise multiplication, and dot product, as well as calculating the transpose and determinant of a square matrix. Additionally, it includes plotting a line graph of the function y = 2x.

Uploaded by

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

Name:Mohini Milind Kapse

import matplotlib.pyplot as plt


Practical:19

import numpy as np
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
matrix1 = np.array([[1, 2, 3],
[4, 5, 6]])
plt.plot(x, y, label="y = 2x", color='blue',
matrix2 = np.array([[7, 8, 9],
marker='o')
[10, 11, 12]])
plt.xlabel('X-axis')
print("Matrix 1:")
plt.ylabel('Y-axis')
print(matrix1)
plt.title('Line Graph: y = 2x')

print("\nMatrix 2:")
plt.grid(True)
print(matrix2)

sum_matrix = np.add(matrix1, matrix2)


plt.legend()
print("\nSum of Matrix 1 and Matrix 2:")
print(sum_matrix)
plt.show()
product_matrix = np.multiply(matrix1, matrix2)
print("\nElement-wise multiplication of Matrix 1
and Matrix 2:")
print(product_matrix)

dot_product_matrix = np.dot(matrix1,
matrix2.T)
print("\nDot product of Matrix 1 and Matrix 2
(after transpose):")
print(dot_product_matrix)

transpose_matrix1 = np.transpose(matrix1)
print("\nTranspose of Matrix 1:")
print(transpose_matrix1)

matrix_square = np.array([[1, 2], [3, 4]])


determinant = np.linalg.det(matrix_square)
print("\nDeterminant of the square matrix:")
print(determinant)

You might also like