0

I have an array containing images of data as follows.

print(np.shape(input_data_transformed))

(120, 120, 1, 589)

Here input_data_transformed is NumPy array having 589 images stored in it. Each image is 120x120 in size with a single channel.

I have another NumPy array called index array as follows.

index_array=np.array([  8,   9,  10,  11, ..............., 584, 585, 586])

I want to select images from input_data_transformed as per the index values in index_array

So the final_filtered_data should contain only those images data, the index of which is given in the index_array

final_filtered_data=?

1 Answer 1

1

Seems like your dimensions are in the wrong order. You could transpose and then just index on the first axis:

input_data_transformed.transpose(3,2,0,1)[index_array]

Checking with an example:

a = np.random.rand(120, 120, 1, 589)
index_array=np.array([  8,   9,  10,  11, 584, 585, 586])

a.transpose(3,2,0,1)[index_array].shape
# (7, 1, 120, 120)
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.