I am new to Numpy and want to replace part of the matrix. For example, I have two matrices: A, B generated by numpy
In [333]: A = ones((5,5))
In [334]: A
Out[334]:
array([[ 1., 1., 1., 1., 1.],
[ 1., 1., 1., 1., 1.],
[ 1., 1., 1., 1., 1.],
[ 1., 1., 1., 1., 1.],
[ 1., 1., 1., 1., 1.]])
In [335]: B
Out[335]:
array([[ 0.1, 0.2],
[ 0.3, 0.4]])
In the end, I want to make A the next matrix.
In [336]: A
Out[336]:
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]])
and / or following
In [336]: A
Out[336]:
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.]])
I tried to follow, but it did not work. Now I do not know :(
A[[0,1],:][:,[3,4]] = B
or even i tried like
A[[0,1],:][:,[3,4]] = 1
to check if four cells are changed. Do you have any ideas?