【发布时间】:2020-05-02 18:46:56
【问题描述】:
我需要在 2d 矩阵中填写缺失值(以 0 表示)。 我将如何在 numpy/scipy 中完成它? 我找到了scipy.interpolate.interp2d 函数,但我不太明白如何在不修改非零条目的情况下使其仅填充零。
这里是这个函数用于平滑图像https://scipython.com/book/chapter-8-scipy/examples/scipyinterpolateinterp2d/的示例
但这不是我想要的。我只想填写零值。
比如矩阵是
import numpy as np
mat = np.array([[1,2,0,0,4], [1,0,0,0,8], [0,4,2,2,0], [0,0,0,0,8], [1,0,0,0,1]])
mat
array([[1, 2, 0, 0, 4],
[1, 0, 0, 0, 8],
[0, 4, 2, 2, 0],
[0, 0, 0, 0, 8],
[1, 0, 0, 0, 1]])
在此矩阵中,所有零都必须替换为插值,而原始值应保持不变。 我可以用什么来完成这项任务?
【问题讨论】:
-
你要填什么?哪些价值观?
-
@rammelmueller 全为零
标签: python numpy scipy interpolation