Question

python slove matrix inner product without numpy A: 5x5 matrix, B: 5x5 matrix (make array and...

python

slove matrix inner product without numpy

A: 5x5 matrix, B: 5x5 matrix

(make array and use loop ?)  

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Python Code:

Output:

Above code:

# Program to get inner product of two 5 x 5 matrix A and B using loops

# A matrix of the size 5x5

A = [[1,7,3,5,6],

[1,2,4,5,6],

[6,3,7,8,9],

[2,8,6,4,3],

[1,3,8,6,4]]

# B matrix of the size 5x5

B = [[4,8,1,2,7],

[6,7,3,2,2],

[4,1,2,1,8],

[1,2,4,4,8],

[4,6,8,6,8]]

# Ineer product result is matrix of the size 5x5

InnerProduct = [[0,0,0,0,0],

[0,0,0,0,0],

[0,0,0,0,0],

[0,0,0,0,0],

[0,0,0,0,0]]

# iteration through A's rows

for i in range(len(A)):

# iteration through B's columns

for j in range(len(B[0])):

# iteration through B's rows

for k in range(len(B)):

InnerProduct[i][j] += A[i][k] * B[k][j]

print("Inner Product Result is:")

for result in InnerProduct:

print(result)

Add a comment
Know the answer?
Add Answer to:
python slove matrix inner product without numpy A: 5x5 matrix, B: 5x5 matrix (make array and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT