参考这篇文章的代码封装了一个类似Matlab中的magic函数,用来生成魔方矩阵. #!/usr/bin/env python # -*- coding: utf-8 -*- import numpy as np def magic(n): row,col=0,n//2 magic=[] for i in range(n): magic.append([0]*n) magic[row][col]=1 for i in range(2,n*n+1): r,l=(row-1+n)%n,(col+1)
先学习一下matlab中CRC函数. 语法如下: h = crc.generator(‘Polynomial', polynomial, ‘param1', val1, etc.) 再看一个例子就比较好容易理解, % Construct a CRC generator with a polynomial defined % by x^3+x+1, with zero initial states, % and with an all-ones final XOR value: h = crc.g