I am trying to select rows with values in their first two columns matching with those of another array and set their last columns values to the last column values of that array.
I've specifically tried to do something like this:
import numpy as np
array_1 = np.zeros((10,3), order = "F", dtype = int)
array_2 = np.zeros((5,3), order = "F", dtype = int)
array_1[:5][:,0] = 1
array_1[:5][:,1] = 1
array_2[:,0] = 1
array_2[:,1] = 1
array_2[:,2] = 3
array_1[:,2][np.where((array_1[:,0] == array_2[:,0]) & (array_1[:,1] == array_2[:,1]))] = array_2[:,2]
The objective is to set the value of column 2 of rows matching to 3. (same as array_2)
I've also tried to do the same thing with masking.
It always complaints about a shape mismatch, so I assume I am doing something wrong since the objective is only to change the value of one particular column, for those row matches.
What is the way to do this?
array_1andarray_2?array_1[:,0].shapeandarray_2[:,0].shape? If they are different, you cannot compare them.array_1andarray_2that demonstrates the problem and is representative of your actual arrays.