我正在寻找一种方法来重新缩放一个numpy2d数组到任意维,这样重缩放数组中的每个单元都包含它(部分)覆盖的所有单元的加权平均值。在
如果新维度是原始维度的倍数,我已经找到了几种方法来实现这一点。例如,给定一个4x4数组,可以将其重新缩放为2x2数组,其中第一个单元格是原始单元格中左上4个单元格的平均值。但是这些方法似乎都不起作用,例如从4x4数组转换为3x3数组。在
这张图说明了在从4x4(黑色网格)到3x3(红色网格)的情况下我想做什么: https://www.dropbox.com/s/iutym4frcphcef2/regrid.png?dl=0
较小阵列中的单元(0,0)覆盖整个单元(0,0)和单元(1,0)、(0,1)和(1,1)的部分。我希望新的单元格包含这些单元格的平均值,这些单元格按黄色、绿色、蓝色和橙色区域的面积加权。在
有没有办法让numpy/scipy做到这一点?有没有这种重新划分的名称(在搜索方法时会有帮助)?在
给你:
它使用^{} 包来轻松地计算不同网格单元的重叠,因此您需要获取它。在
以下是几个具有不同网格的示例:
下采样也是可能的。
做完这些之后,我很确定我所做的只是某种形式的image sampling。如果你想在大名单上做这件事,那么你就需要让事情变得更有效率,因为这会很慢。在
相关问题 更多 >
编程相关推荐