I'm trying to understand a script in Python for an assignment but I don't know what square brackets mean when used in a variable's name. This is the code:
import numpy as np
if __name__ == "__main__":
epsilonff = 94.45
sigmaff = 3.575
delta = 0.01*sigmaff
L = 10*sigmaff
rhob = 0.004959169999999999/sigmaff**3
kT = 77.4
beta = 1.0/kT
sigmasf, epssf, rhov, Delta = 3.494, 53.22, 0.114, 3.35
x = np.arange(0,L,delta) 0.5*delta
N = x.size
def Vsteele(z,sigmaw,epsw,rhov,Delta):
return 2*np.pi*rhov*epsw*sigmaw**2*Delta*((sigmaw/z)**10-(sigmaw/z)**4-sigmaw**4/(3*Delta*(z 0.61*Delta)**3))
Vext = beta*Vsteele(x,sigmasf,epssf,rhov,Delta) beta*Vsteele(L-x,sigmasf,epssf,rhov,Delta)
print(f'rhob is = {rhob}')
rhob is = 1.08537761e-04
I can understand that, but the following I don't get.
n = rhob*np.ones(N,dtype=np.float32)
nsig = int(0.5*sigmaff/delta)
mask = Vext>beta*1e4
n[mask] = 1.0e-16
Vext[mask] = beta*1e4
Shouldn't the first line make an array of 1s with length N? yet this is my output: (I'd say is because of the squared brackets but I don't how do they affect)
[1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.08537761e-04 1.08537761e-04 1.08537761e-04
1.08537761e-04 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16
1.00000000e-16 1.00000000e-16 1.00000000e-16 1.00000000e-16]
CodePudding user response:
Square brackets are used in Python to index into or slice list-like objects. NumPy extends the base index functionality and allows boolean expressions to select subsets of its array objects. In your case, you are modifying every value in the array that satisfies the mask
condition.
See the Python documentation: An Informal Introduction to Python - Lists
and the NumPy docs: Indexing on ndarrays