Numpy vectorize wrongly converts the output to be integer
问题 I am struggling with the following code: import numpy as np e = np.linspace(0, 4, 10) def g(x): if x > 1: return x else: return 0 vg = np.vectorize(g) print(vg(e)) the result looks like this: [0 0 0 1 1 2 2 3 3 4] I also checked the dtype. It seems that the vectorize function is conveting the type to int64 from float64! 回答1: The documentation for np.vectorize explains: The data type of the output of vectorized is determined by calling the function with the first element of the input. This can