Replace sub part of matrix by another small matrix in numpy

Here is how you can do it:

>>> A[3:5, 3:5] = B
>>> A
array([[ 1. ,  1. ,  1. ,  1. ,  1. ],
       [ 1. ,  1. ,  1. ,  1. ,  1. ],
       [ 1. ,  1. ,  1. ,  1. ,  1. ],
       [ 1. ,  1. ,  1. ,  0.1,  0.2],
       [ 1. ,  1. ,  1. ,  0.3,  0.4]])

Leave a Comment