对NumPy数组(2D)进行过采样

3
有没有在numpy / scipy中过采样2D numpy数组的函数?
例如:
>>> x = [[1,2]
     [3,4]]
>>> 
>>> y = oversample(x, (2, 3))

将返回

y = [[1,1,2,2],
     [1,1,2,2],
     [1,1,2,2],
     [3,3,4,4],
     [3,3,4,4],
     [3,3,4,4]]

目前我已经实现了自己的函数:

index_x = np.arange(newdim) / olddim
index_y = np.arange(newdim) / olddim

xx, yy = np.meshgrid(index_x, index_y)
return x[yy, xx, ...]

但它似乎不是最好的方法,因为它只适用于2D重塑,并且有点慢...

有什么建议吗? 非常感谢

1个回答

1

编辑 发帖后才看到评论,如果需要请删除

原文 检查np.repeat以重复模式。 显示详细信息

>>> import numpy as np
>>> a = np.array([[1,2],[3,4]])
>>> a
array([[1, 2],
       [3, 4]])
>>> b=a.repeat(3,axis=0)
>>> b
array([[1, 2],
       [1, 2],
       [1, 2],
       [3, 4],
       [3, 4],
       [3, 4]])
>>> c = b.repeat(2,axis=1)
>>> c
array([[1, 1, 2, 2],
       [1, 1, 2, 2],
       [1, 1, 2, 2],
       [3, 3, 4, 4],
       [3, 3, 4, 4],
       [3, 3, 4, 4]])

是的...在发布之前确实查找了答案...对此很抱歉,但还是感谢您的回答! - Lorenzo Trojan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接