I am new to Numpy and want to replace part of a matrix. For example, I have two matrices, A, B generated by numpy
In [333]: A = ones((5,5))
In [334]: A
Out[
For the first one:
In [13]: A[-B.shape[0]:, -B.shape[1]:] = B
In [14]: A
Out[14]:
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]])
For second:
In [15]: A = np.ones((5,5))
In [16]: A[:B.shape[0], -B.shape[1]:] = B
In [17]: A
Out[17]:
array([[ 1. , 1. , 1. , 0.1, 0.2],
[ 1. , 1. , 1. , 0.3, 0.4],
[ 1. , 1. , 1. , 1. , 1. ],
[ 1. , 1. , 1. , 1. , 1. ],
[ 1. , 1. , 1. , 1. , 1. ]])