How to convert image to csv

hello sir i prepared the final image but i am not able to convert it to csv file its showing error in the way u converted a 2D structure into csv

Hey @gaurangagarwal557, lets suppose ‘ans’ is the variable having final image as answer. You can follow like this,
ans = ans.reshape((-1,3))

and after that you can simply convert it into csv.
import pandas as pd
pd.DataFrame(ans).to_csv(“solution.csv”, header = [‘r’,‘g’,‘b’], index = False)

Hope this resolved your doubt. :blush:

yes it worked thank you very much
sir can u explain why reshape(-1,3) i mean what did -1 did.

Hey @gaurangagarwal557, so this is the feature of numpy i can specify one shape parameter as -1, which means its value will be calculated automatically. Initially ans.shape (height, width, 3) and after i reshaped it, i can do it either way 1. ans.reshape( height*width , 3) or ans.reshape(-1,3) both are equivalent.

Hope this resolved your doubt. :blush:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.