在该方法tom10的回答可以扩展到任意尺寸:
def shear3(a, strength=1, shift_axis=0, increase_axis=1): if shift_axis > increase_axis: shift_axis -= 1 res = numpy.empty_like(a) index = numpy.index_exp[:] * increase_axis roll = numpy.roll for i in range(0, a.shape[increase_axis]): index_i = index + (i,) res[index_i] = roll(a[index_i], -i * strength, shift_axis) return res
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)