Numpy - overlay 2 matrices at a specific location

Good day,

Let's say I have a 200 * 200 A matrix and a 50 * 50 B matrix. I want B to be placed at point A at address (175,175). The problem is that B exceeds the bounds of A, but I really need the exceeded bounds to be lifted.

I tried to do something like this: A [y: yRange + y, x: xRange + x] = B, but this will throw an out of bounds error. Is there an easy way to overlap these 2 in position without resorting to a slow loop.

0


source to share


1 answer


You can copy chunk B

to chunk A

like:

 A[175:, 175:] = B[:25, :25]

      



This is a direct use of indexing numpy

.

0


source







All Articles