标签:median constant value ima 有关 不同 维数 dia 学习
np.pad()常用与深度学习中的数据预处理,可以将numpy数组按指定的方法填充成指定的形状。
import numpy as np arr1D = np.array([1, 1, 2, 2, 3, 4]) ‘‘‘不同的填充方法‘‘‘ print ‘constant: ‘ + str(np.pad(arr1D, (2, 3), ‘constant‘)) print ‘edge: ‘ + str(np.pad(arr1D, (2, 3), ‘edge‘)) print ‘linear_ramp: ‘ + str(np.pad(arr1D, (2, 3), ‘linear_ramp‘)) print ‘maximum: ‘ + str(np.pad(arr1D, (2, 3), ‘maximum‘)) print ‘mean: ‘ + str(np.pad(arr1D, (2, 3), ‘mean‘)) print ‘median: ‘ + str(np.pad(arr1D, (2, 3), ‘median‘)) print ‘minimum: ‘ + str(np.pad(arr1D, (2, 3), ‘minimum‘)) print ‘reflect: ‘ + str(np.pad(arr1D, (2, 3), ‘reflect‘)) print ‘symmetric: ‘ + str(np.pad(arr1D, (2, 3), ‘symmetric‘)) print ‘wrap: ‘ + str(np.pad(arr1D, (2, 3), ‘wrap‘))
constant_values=(x, y)
时前面用x填充,后面用y填充。缺参数是为0000。。。import numpy as np arr3D = np.array([[[1, 1, 2, 2, 3, 4], [1, 1, 2, 2, 3, 4], [1, 1, 2, 2, 3, 4]], [[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], [[1, 1, 2, 2, 3, 4], [1, 1, 2, 2, 3, 4], [1, 1, 2, 2, 3, 4]]]) ‘‘‘对于多维数组‘‘‘ print ‘constant: \n‘ + str(np.pad(arr3D, ((0, 0), (1, 1), (2, 2)), ‘constant‘)) print ‘edge: \n‘ + str(np.pad(arr3D, ((0, 0), (1, 1), (2, 2)), ‘edge‘)) print ‘linear_ramp: \n‘ + str(np.pad(arr3D, ((0, 0), (1, 1), (2, 2)), ‘linear_ramp‘)) print ‘maximum: \n‘ + str(np.pad(arr3D, ((0, 0), (1, 1), (2, 2)), ‘maximum‘)) print ‘mean: \n‘ + str(np.pad(arr3D, ((0, 0), (1, 1), (2, 2)), ‘mean‘)) print ‘median: \n‘ + str(np.pad(arr3D, ((0, 0), (1, 1), (2, 2)), ‘median‘)) print ‘minimum: \n‘ + str(np.pad(arr3D, ((0, 0), (1, 1), (2, 2)), ‘minimum‘)) print ‘reflect: \n‘ + str(np.pad(arr3D, ((0, 0), (1, 1), (2, 2)), ‘reflect‘)) print ‘symmetric: \n‘ + str(np.pad(arr3D, ((0, 0), (1, 1), (2, 2)), ‘symmetric‘)) print ‘wrap: \n‘ + str(np.pad(arr3D, ((0, 0), (1, 1), (2, 2)), ‘wrap‘))
标签:median constant value ima 有关 不同 维数 dia 学习
原文地址:https://www.cnblogs.com/zongfa/p/8995739.html