0

I am trying to convert a black and white picture, represented as a numpy array with the shape (640,480,1) - where 640 is the x value, - 480 the y value, and the last one either a 0 or a 1 representing the mask. Now I am trying to covert this array in a (640*480,2) array, where the rows represent 0 or 1, and the columns represent the x and y value. I have absolutely no clue on how to do that. Any help is appreciated.

1 Answer 1

1

It sounds like you're one-hot encoding (I think) and the easiest way to do that with numpy is by indexing np.eye(number_of_categories)

img = np.random.randint(2, (640,480,1))
out = np.eye(2)[img.ravel()]

out.shape
Out[]: (307200, 2)

Not sure why you'd want to one-hot encode a binary value though.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.