Question: Write a Python program to check whether a NumPy array is a magic matrix. A magic square is a matrix all of whose row sums,

Write a Python program to check whether a NumPy array is a magic matrix. A magic square is a matrix all of whose row sums, column sums and the sums of the two diagonals are the same.
Suppose that we have an array A=np.array([[17,24,1,8,15],[23,5,7,14,16],[4,6,13,20,
22],[10,12,19,21,3],[11,18,25,2,9]]). The matrix A has 5 row sums (one for each row),5 column sums (one for each column) and two diagonal sums. These 12 sums should all be exactly the same.
The following inputs are given:
A=([[17,24,1,8,15],
[23,5,7,14,16],
[4,6,13,20,22],
[10,12,19,21,3],
[11,18,25,2,9]]
B =[[17,24,1,8,15],
[23,5,7,14,16],
[4,6,13,20,22],
[10,12,19,21,3],
[11,18,25,2,9]]
C = a 5 by 5 matrix of ones
test_input =[A,B,A+B,A-B,A-C,B+C,A*B]
The expected output is:
[True, True, True, True, True, True, False]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!