自己编写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]
原文地址:https://www.cnblogs.com/anyview/p/5579836.html