1
我试图复制一个2D numpy的数组的边界:复制边界
>>> from numpy import *
>>> test = array(range(9)).reshape(3,3)
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
有没有一种简单的方法在任何方向上复制一个边界?
例如:
>>>> replicate(test, idx=0, axis=0, n=3)
array([[0, 1, 2],
[0, 1, 2],
[0, 1, 2],
[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
编辑:
以下功能做了工作:
def replicate(a, xy, se, n):
rptIdx = numpy.ones(a.shape[0 if xy == 'X' else 1], dtype=int)
rptIdx[0 if se == 'start' else -1] = n + 1
return numpy.repeat(a, rptIdx, axis=0 if xy == 'X' else 1)
在[ 'X', 'Y']和SE XY在['start','end'中]
谢谢。我想我可以用'ones_like'和'repeat'来得到我想要的。 – Simon 2011-04-11 16:51:48