在我的程序中,我有一个numpy数组,并对其进行一些卷积过滤.我正在寻找一些方法来使用numpy轻松进行数组填充(然后输出unpad)以避免边界检查.我知道scipy可以做卷积,但我有理由自己做.gnuplot.py用于输出.
def touch(field, coords, value):
field[coords[0], coords[1]] = value
if coords[0] - 1 > 0:
field[coords[0] - 1, coords[1]] = value / 2
if coords[1] - 1 > 0:
field[coords[0], coords[1] - 1] = value / 2
if coords[0] < field.shape[0] - 1:
field[coords[0] + 1, coords[1]] = value / 2
if coords[1] < field.shape[1] - 1:
field[coords[0], coords[1] + 1] = value / 2
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3165 次 |
| 最近记录: |