图片数据扁平化的方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Solo95/article/details/84328884

A image in computer is represent in as matrix(height, width, 3), 3 represent three values of R,G,B.

For convenience, you should now reshape images of shape (num_px, num_px, 3) in a numpy-array of shape (num_px ∗ num_px ∗ 3, 1). Here num_px = height = width

A trick when you want to flatten a matrix X of shape (a,b,c,d) to a matrix X_flatten of shape (b ∗ c ∗ d, a) is to use:

X_flatten = X.reshape(X.shape[0], -1).T      # X.T is the transpose of X

猜你喜欢

转载自blog.csdn.net/Solo95/article/details/84328884