2015-10-12 72 views
0

在numpy/scipy中是否有過度採樣2D numpy數組的函數?Oversample Numpy Array(2D)

例如:

>>> 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

EDIT沒有看到評論後,直到後,刪除如果需要

原始 檢查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]]) 
+0

是啊......在發帖之前確實找過答案......對此感到抱歉,但無論如何感謝您的回答! –