How to insert small array into larger array without fully specifying destination slices?

Say we are pasting a smaller image into a larger one. We could do it the normal way,

large = np.zeros((3, 100, 100)) small = np.ones((3, 10, 10)) large[:, :10, :10] = small 

but sometimes it would be more convenient if we didn’t have to specify the target range.

Is something like this possible in numpy?

large[:, 0, 0] = small  # paste (3, 10, 10) image into (0, 0) location large[:, 50, 50] = small  # paste (3, 10, 10) image into (50, 50) location 
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.