i have the code like below
H = [10 20 30 40 50 60]
b = [5 9 28 59 22 18]
g = [9 9 10 25 30 5]
H(b < g) = 2*100 - H(b < g)
the result is like this :
H(b < g) = 2*100 – H(b < g)
i think this code means that if(b[index] < g[index]) then H[index] = 2*100 – H[index]
is my understanding is correct?
is there way in python to do it without looping for the index? thankyou
>Solution :
Since you’re already using numpy, translating MATLAB is quite straightforward: just change the parentheses to brackets.
H = np.array([10, 20, 30, 40, 50, 60])
b = np.array([5, 9, 28, 59, 22, 18])
g = np.array([9, 9, 10, 25, 30, 5])
H[b < g] = 2*100 - H[b < g]
Which gives the desired H:
array([190, 20, 30, 40, 150, 60])
Here’s a handy resource for translating MATLAB to numpy: https://numpy.org/doc/stable/user/numpy-for-matlab-users.html
