Reputation: 47
I try to insert values from one matrix into another. The first is 1-D and the second is 2-D matrix. I want to insert the values so that the values from the 1-D matrix I want to give to the last row and the values that increase will go to the last column in the second matrix. This is better illustrated by an example.The matrices can be of different sizes, but always to cover the last row and column as shown in the example
example
input
b=np.array([[13,14,15],
[22,23,24],
[31,32,33]])
d=np.array([100,200,300,400,500])
required output
13 14 500
22 23 400
100 200 300
or
input2
b=np.array([[12,13,14,15],
[21,22,23,24]])
d=np.array([100,200,300,400,500])
required output2
12 13 14 500
100 200 300 400
Upvotes: 0
Views: 196
Reputation: 2525
I would split up the problem into two assignments:
b[-1,:]=d[:b.shape[1]] # last row
b[:-1,-1]=d[:b.shape[1]-1:-1] #last column minus element from last row
Upvotes: 2