numpy with python: convert 3d array to 2d

前端 未结 3 569
一生所求
一生所求 2020-12-03 01:23

Say that I have a color image, and naturally this will be represented by a 3-dimensional array in python, say of shape (n x m x 3) and call it img.

I want a new 2-d

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-03 02:07

    Let's say we have an array img of size m x n x 3 to transform into an array new_img of size 3 x (m*n)

    new_img = img.reshape((img.shape[0]*img.shape[1]), img.shape[2])
    new_img = new_img.transpose()
    

提交回复
热议问题