0

I have a list object named " imgs " of tensors (50 images). I have an array of indices (indi) of length 29.

how do I index the list of tensors with the array of indices?

when I do the following I get:

imgs[indi] 

TypeError: only integer scalar arrays can be converted to a scalar index

Thanks

1 Answer 1

1

Assuming these are normal python lists then you can use a list comprehension

result = [imgs[i] for i in indi]

which will give a list of tensors.

If you further want to make this a single tensor containing the images you can use torch.stack

result = torch.stack([imgs[i] for i in indi], dim=0)

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.