numpy - yszheda/wiki GitHub Wiki
isinstance(y, (np.ndarray, np.generic) )
convertfunc = lambda x: float(x.strip(b"%"))/100
b = np.genfromtxt(io.BytesIO(data.encode()), names = names, delimiter = ",", converters = {1:convertfunc})
numpy.vectorize
correlation
- Correlation in Python
- https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.pyplot.xcorr.html
- Plot correlation matrix using pandas
print numpy array
import sys
import numpy
numpy.set_printoptions(threshold=sys.maxsize)
import numpy as np
np.set_printoptions(formatter={'int':hex})
import numpy as np
np.set_printoptions(edgeitems=3)
save / load
np.save(fname, x)
np.load(fname + '.npy')
round
numpy.round is round half to even (IEEE 754)
- Rounding to nearest int with numpy.rint() not consistent for .5
- Round number to nearest integer
- How to properly round-up half float numbers?
- Error "TypeError: type numpy.ndarray doesn't define round method"
- Round number to nearest integer
import numpy as np
def round_half_up(x):
round_lambda = lambda z: (int(z > 0) - int(z < 0)) * int(abs(z) + 0.5)
if isinstance(x, (np.ndarray, np.generic)):
return np.vectorize(round_lambda)(x)
else:
return round_lambda(x)