Relative Content

Tag Archive for pythonnumpy

rounding floating point number ending with .5 half to even

How can I round a floating-point number to the nearest even digit with a precision of 4 decimal places in Python? I tried using the np.round function and the built-in round function, but they don’t seem to work for me. For example, with a negative number like -2.6825, I want the rounding to give me -2.6830, but it currently gives me -2.6820. What is the way to achieve rounding half to even?

Speed up / parallelize multivariate_normal.pdf

I have multiple Nx3 points, and I sequentially generate a new value for each from its corresponding multivariate Gaussian, each with 1×3 mean and 3×3 cov. So, together, I have arrays: Nx3 array of points, Nx3 array of means and Nx3x3 array of covs.

Convert ‘3’ to numpy.dtypes.Int64DType

I have strings containing str representations of numpy values. I also have a list of the original dtypes, such as numpy.dtypes.Int64DType. I do not know all possible dtypes in advance. I can for the life of me not figure out how to convert the string back to a scalar of the correct dtype.