问题描述
我有一个一维数组,我想围绕它的中心旋转它以生成一个对称的二维数组。我该怎么做?
例如,我通过 scipy 定义了一个一维窗口数组,现在我想生成它的具有旋转对称性的二维版本。但是,numpy.outer
的结果不具有旋转对称性。
from scipy.signal import windows
import matplotlib.pyplot as plt
exp1 = windows.get_window(('exponential',None,5),60)
exp2d = np.sqrt(np.outer(exp1,exp1))
plt.imshow(exp2d)
我意识到如果一维窗口具有解析形式,那么做起来很简单。但是,对于没有解析形式的任意一维数组(函数),是否有一些通用的方法?
解决方法
是的,这是可以做到的。这是一种可能的方法:
-
像这样生成一个“半径”图像,其中每个点的像素值是它与中心的距离:
-
计算
f(radius)
,其中f
是任何一维函数。例如:或者,如果您有一个一维数组而不是函数,例如使用 scipy.interpolate.interp1d 插入它,例如
f = interpolate.interp1d(x,y)
。