Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

More Books

Students also viewed these Databases questions

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago