【问题标题】:Oversample Numpy Array (2D) [duplicate]过采样 Numpy 数组(2D)[重复]
【发布时间】:2015-10-12 07:33:33
【问题描述】:

numpy/scipy 中是否有对二维 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 重塑并且有点慢......

有什么建议吗? 非常感谢

【问题讨论】:

    标签: python arrays numpy


    【解决方案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]])
    

    【讨论】:

    • 是的...在发布之前确实四处寻找答案...对此感到抱歉,但无论如何感谢您的回答!
    猜你喜欢
    • 1970-01-01
    • 2018-02-02
    • 2016-03-11
    • 2015-05-19
    • 1970-01-01
    • 2020-05-22
    • 2021-11-24
    • 1970-01-01
    • 2017-12-19
    相关资源
    最近更新 更多