print(figure_handle,'formats','-rnumber','filename') %将图形保存为png格式,分辨率为number的(默认为72),最好指定的分辨率大一点,否则保存图形的效果较差. %Save the figure with the handle h to a PostScript file named Figure1, which can be printed later: h = figure; %指定图片打印figure handle plo
参考这篇文章的代码封装了一个类似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)