I am struggling to understand a script. The aim is to write a function. One of the equation from the function is:
And the script that I am trying to understand does it like this:
g_star = g_eff+(g-g_eff)*h/B
g_star[h>B] = g
I can understand if I normally use "if h>B : ". However, if I tried to recreate similar command with an if function like this:
a = 3
c = a - 5
c[a<5] = a+1
print(c)
In above scenario, c should be 4. But I got an error saying: error message
Could someone please explain to me why is the if function using square bracket worked in the first example, but not in the second example? Is using a square bracket really a more efficient way than using the old-fashioned "if" function?
Thank you very much for your time and attention.
Kind regards, Rayyan
Aucun commentaire:
Enregistrer un commentaire