自己编写shave函数

import numpy

def shave(I,border=None):
	I = I[border[0]:I.shape[0]-border[0],border[1]:I.shape[1]-border[1]]
	return I

x = numpy.zeros([5,5])

x[1:4,1:4] = 2
print x

y =shave(x,[1,1])
print y

  运行结果:

[[ 0.  0.  0.  0.  0.]
 [ 0.  2.  2.  2.  0.]
 [ 0.  2.  2.  2.  0.]
 [ 0.  2.  2.  2.  0.]
 [ 0.  0.  0.  0.  0.]]
[[ 2.  2.  2.]
 [ 2.  2.  2.]
 [ 2.  2.  2.]]
[Finished in 0.2s]

 

posted @ 2016-06-13 10:48  视觉书虫  阅读(741)  评论(0编辑  收藏  举报