I have two matrixes
A = array([[ 12., 0.],[ 0., 4.]])
B = array([[ 13., 5.],[ -1., -5.]])
and I want to get a third one whose elements correspond to the maximum of the previous matrixes. For instance I would like to produce something like
C = array([[ 13., 5.],[ 0., 4.]])
Is there any vectorial operation I could do to make the result faster?
It is easier to use numpy array instead of arrays. With a numpy array you have the np.where function to solve this:
This works like : np.where(condition, [returnvalue if true, returnvalue if false])
If you don’t pass the optional return parameters, you will get an array with the indexes where the condition is true.