Pls. NumPy Only:
import numpy as np
A = np.ones((5,5))*3
print A
[[ 3. 3. 3. 3. 3.]
[ 3. 3. 3. 3. 3.]
[ 3. 3. 3. 3. 3.]
[ 3. 3. 3. 3. 3.]
[ 3. 3. 3. 3. 3.]]
B = np.ones((5,5))*5
print B
[[ 5. 5. 5. 5. 5.]
[ 5. 5. 5. 5. 5.]
[ 5. 5. 5. 5. 5.]
[ 5. 5. 5. 5. 5.]
[ 5. 5. 5. 5. 5.]]
C = np.ones((5,5))
C[0:2,0:2] = 99
print C
[[ 99. 99. 1. 1. 1.]
[ 99. 99. 1. 1. 1.]
[ 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1.]]
A, B, and C are the given conditions. I want to calculate the maximum between A, B where the C values are 99; and put the results into A. The following code works correctly.
A[C==99] = np.max([A, B],axis=0)[C==99]
print A
The expected result is:
[[ 5. 5. 3. 3. 3.]
[ 5. 5. 3. 3. 3.]
[ 3. 3. 3. 3. 3.]
[ 3. 3. 3. 3. 3.]
[ 3. 3. 3. 3. 3.]]
However, I am wondering if there is better way of solving it. I mean more simplier, faster, or easier way...