我有一个48x80大小的数组,现在我想将这个数组扩展到117x192大小的新数组。
我读过scipy.interpolate,但它没有提到扩展。在
如何扩展数组并将值放入新数组?在
例如: 给定数组A[[1,2,3],[4,5,6],[7,8,9]]
[1 2 3]
[4 5 6]
[7 8 9]
现在我想将数组A扩展到数组B,大小为5x7
^{pr2}$其中,将这些“x”替换为插值值。在
例2: 在更一般的数组中
[4 2 6 4]
[4 34 6 2]
[2 11 3 4]
[2 4 22 4]
[2 1 35 255]
[1 3 4 54]
[22 1 4 5]
如果我想要一个20x30大小的新数组,我该怎么办
更新: 我发现有一点不同,@nicoguaro答案在我的案例中不起作用:
他的解决方案:
pts = np.array([[i,j] for i in np.linspace(0,1,n) for j in np.linspace(0,1,m)] )
grid_x, grid_y = np.mgrid[0:1:m*2j, 0:1:n*2j]
我的解决方案:
pts = np.array([[i,j] for i in np.linspace(0,2*m-1,m) for j in np.linspace(0,2*n-1,n)] )
grid_x, grid_y = np.mgrid[0:m*2, 0:n*2]
这导致了不同的结果。事实上,他的解决方案在大多数情况下都是有效的,但我想是TIFF文件
虽然interpolate没有用于此特定任务的函数,但您可以轻松地使用内置选项来执行此操作。用你建议的同样的例子
到
^{pr2}$我们可以用这个密码
结果就是这样
或者,作为图像
在本例中,我使用了
griddata
,它将一组点(pts
)上定义的集函数(vals
)插值到给定的直线网格(由grid_x
和grid_y
)插值。例如,如果您想对$x$使用nx
点,而对$y$使用ny
,则可以替换一行对于
nx=20
和ny=15
我们得到了这张图片您可以在documentation of the function上看到更多示例。在
更新:包括示例2,其中矩阵
以及一个尺寸为20x30的新阵列。代码如下
生成的图像是: ^{5美元
相关问题 更多 >
编程相关推荐