我想把它插值到一个4单元的网格上。每个单元格将只包含其内部所有点的平均值。
输出应该是这样的
因此,我们将整个数据转换为2x2矩阵。此矩阵的每个单元格将具有其内部所有点的平均x坐标和平均y坐标值。在
A1=(3,-3);A2=(3.5,1.5)
A3=(-1,-3);A4=(-2,1)
我尝试了什么=====
avg = [[
(
( mat[row][col][0]
+ mat[row][col+1][0]
+ mat[row+1][col][0]
+ mat[row+1][col+1][0] ) / 4.0
,
( mat[row][col][1]
+ mat[row][col+1][1]
+ mat[row+1][col][1]
+ mat[row+1][col+1][1] ) / 4.0
)
for col in range(0, len(mat[0]), 2) ]
for row in range(0, len(mat), 2)
]
我对numpy/scipy不太在行,我认为这在优雅和效率方面可以得到极大的改进,但它确实有效:
-> jupyter notebook with intermediate plots
最终代码:
相关问题 更多 >
编程相关推荐