How to convert a image into csv file of (height*width,3)

instagram style phot collage after forming the final collage image it i am stuck that how i will convert this 4304303 size matrix to csv file of (430*430,3)

Hey @abubakar_nsit, say your img is the variable having 434303. Further follow this steps,

import pandas as pd

img = np.reshape(img,(-1,3))
pd.DataFrame(data = img).to_csv(“submission.csv”, header = [‘r’,‘g’,‘b’], index = False)

Hope this resolved your doubt.
Plz mark the doubt as resolved in my doubts section. :blush:

thank u sir!:slightly_smiling_face:

Hey @abubakar_nsit, -1 means we are not sure about number of rows, so the program will automatically figure out itself. Suppose img.shape initially be (100,100,3) and we used img = np.reshape(img,(-1,3)), than now img.shape = (10000,3). For generalization if img.shape = (x,y,3) initially than after applying it, the shape of img be (x*y,3).

Hope this resolved your doubt.
Plz mark the doubt as resolved in my doubts section. :blush: