0% found this document useful (0 votes)
6 views

Experiment-2 (Matrix Multiplication)

MATRIX MULTIPLICATION
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Experiment-2 (Matrix Multiplication)

MATRIX MULTIPLICATION
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

MULTIPLICATION OF MATRICES

PROGRAM:

#Program For 2x2 matrix Multiplication

import tensorflow as tf

ts1=tf.constant(([1,3],[5,7]),dtype=tf.float32)

ts2=tf.constant(([2,4],[6,8]),dtype=tf.float32)

print("Original Matrix")

print(ts1.numpy())

print(ts2.numpy())

result_tensor=tf.matmul(ts1,ts2)

print("\n Matrix Multiplication Result:")

print(result_tensor.numpy())

#Program For 3x3 matrix Multiplication

import tensorflow as tf

import numpy as np

matrix_1=np.array([[1,2,3],[3,2,1],[1,1,1]],dtype='int32')

matrix_2=np.array([[0,0,0],[-1,0,1],[3,3,4]],dtype='int32')

print("The First Matrix Is:")

print(matrix_1)

print("The Second Matrix Is:")

print(matrix_2)

print("The Product Of Matrices Is:")

matrix_1=tf.constant(matrix_1)

matrix_2=tf.constant(matrix_2)

matrix_product=tf.matmul(matrix_1,matrix_2)

print(matrix_product)

NAME: A SOWJANYA REG NO: 22F41A3305


OUTPUT:

#output-1
Original Matrix
[[1. 3.]
[5. 7.]]
[[2. 4.]
[6. 8.]]

Matrix Multiplication Result:


[[20. 28.]
[52. 76.]]

#output-2
The First Matrix Is:
[[1 2 3]
[3 2 1]
[1 1 1]]
The Second Matrix Is:
[[ 0 0 0]
[-1 0 1]
[ 3 3 4]]
The Product Of Matrices Is:
tf.Tensor(
[[ 7 9 14]
[ 1 3 6]
[ 2 3 5]], shape=(3, 3), dtype=int32)

NAME: A SOWJANYA REG NO: 22F41A3305

You might also like