NUMPY note

NUMPY#

np 자리수 조절#

print(U)
> [ 3.40948761e-01  0.00000000e+00 -1.20516241e-01 -3.88578059e-16 -9.32324946e-01 -1.11022302e-16 -2.42574685e-17]


np.set_printoptions(precision=2) # global

with np.printoptions(precision=2, suppress=True): # local
    print(U)
> [ 0.34  0.   -0.12 -0.   -0.93 -0.   -0.  ]

'suppress' about scientific notation
> If True, always print floating point numbers using fixed point notation

U[U < 0] = 0
> [0.34 0.   0.   0.   0.   0.   0.  ]

FILE total line number check#

q = 'wc smiles_100000.txt'
with Popen(q.split(), stdout=PIPE, universal_newlines=True) as process: # 0.043254s
    for i in process.stdout:
        line1 = int(i.split()[0])

w = 0
with open('smiles_100000.txt') as f: # 0.019221s
    for i in f:
        w += 1

with open('smiles_100000.txt') as f: # 0.011087s
    for e, _ in enumerate(f):
        pass

Conclusion : enumerate best.