You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
281 B
Python
17 lines
281 B
Python
11 years ago
|
# -*- coding: utf-8 -*-
|
||
|
"""
|
||
|
Created on Tue Apr 17 13:59:12 2012
|
||
|
|
||
|
@author: pab
|
||
|
"""
|
||
|
import numpy as np
|
||
|
|
||
|
|
||
|
def magic(n):
|
||
|
ix = np.arange(n) + 1
|
||
|
J, I = np.meshgrid(ix, ix)
|
||
|
A = np.mod(I + J - (n + 3) / 2, n)
|
||
|
B = np.mod(I + 2 * J - 2, n)
|
||
|
M = n * A + B + 1
|
||
|
return M
|