NumPy equivalent of Matlab's magic()
问题 In Ocatave / Matlab, I can use magic() to get a magic square, e.g., magic(4) 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1 Definition: A magic square is an N×N grid of numbers in which the entries in each row, column and main diagonal sum to the same number (equal to N(N^2+1)/2 ). How can I generate the same using NumPy? 回答1: This implementation follows Matlab's and should give exactly the same results with the following exception: it throws an error if n < 3 rather than return a non-magic square [