小编jet*_*tta的帖子

Numpy - 标准化RGB像素阵列

我有一个带有形状的numpy数组(34799, 32, 32, 3),意思是(num examples, width, height, channels).

现在我使用以下代码规范化图像数据:

def normalize(x):
    return (x - 128) / 128

X_train_norm = normalize(X_train)
Run Code Online (Sandbox Code Playgroud)

但结果似乎不对,价值X_train[0][0][0][28 25 24],但输出X_train_norm[0][0][0][1.21875 1.1953125 1.1875].

我使用以下测试代码:

test = np.array([[[[28, 25, 24]]]])
print ((test - 128) / 128)
Run Code Online (Sandbox Code Playgroud)

输出:

[[[[-0.78125   -0.8046875 -0.8125   ]]]]
Run Code Online (Sandbox Code Playgroud)

为什么normalize函数得到错误的结果?

python numpy image-processing normalize numpy-broadcasting

8
推荐指数
2
解决办法
7640
查看次数