图像归一化方式:
image/255
img/127.5 - 1
第一种是对图像进行归一化,范围为[0, 1],第二种也是对图像进行归一化,范围为[-1, 1],这两种只是归一化范围不同,为了直观的看出2种区别,分别对图像进行两种处理:
numpy.random.permutation(x) 随机返回一个置换的区间。 打乱区间顺序。仅作用于第一个轴。
If x is a multi-dimensional array, it is only shuffled along its first index.
EXAMPLE HERE:
>>np.random.permutation([1, 4, 9, 12, 15])
array([15, 1, 9, 4, 12])
>>arr = np.arange(9).reshape((3, 3))
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
>>np.random.permutation(arr)
array([[6, 7, 8],
[0, 1, 2],
[3, 4, 5]])
>>permutation = list(np.random.permutation(10))
[5, 1, 7, 6, 8, 9, 4, 0, 2, 3]
>>Y = np.array([[1,1,1,1,0,0,0,0,0,0]])
>>Y_new = Y[:, permutation]
array([[0, 1, 0, 0, 0, 0, 0, 1, 1, 1]])
numpy的allclose方法,比较两个array是不是每一元素都相等,默认在1e-05的误差范围内。
使用如图:
>>> np.allclose([1e10,1e-7], [1.00001e10,1e-8])
False
>>> np.allclose([1e10,1e-8], [1.00001e10,1e-9])
True
>>> np.allclose([1e10,1e-8], [1.0001e10,1e-9])
False
>>> np.allclose([1.0, np.nan], [1.0, np.nan])
False
>>> np.allclose([1.0, np.nan], [1.0, np.nan], equal_nan=True)
True
list 转 numpy array 的时候必须保证每一列的数量都一致。否则将会转换为1纬array。
os.listdir 可能会导致乱序
使用sort()来按字母排序。(数字顺序可能需要别的操作)
file = os.listdir(path);
file.sort()