将 math.erf 应用于数组

782*_*219 2 python numpy function vectorization pandas

我正在使用 math.erf 来查找数组中每个元素的误差函数。

# Import the erf function from the math library
from math import erf
# Import the numpy library to represent the input data
import numpy as np

# Create a dummy np.array
dummy_array = np.arange(20)

# Apply the erf function to the array to calculate the error function of each element
erf_array = erf(dummy_array)
Run Code Online (Sandbox Code Playgroud)

我收到错误,因为我无法将整个函数应用于数组。有没有办法将误差函数应用于整个数组(矢量化方法),而无需循环遍历每个元素并应用它?(由于表很大,循环将花费很多时间)

Ste*_*tef 5

from scipy import special
import numpy as np

dummy_array = np.arange(20)
erf_array = special.erf(dummy_array)
Run Code Online (Sandbox Code Playgroud)

必须将子special包导入为from scipy import special. scipy正如此处此处所解释的那样,导入import scipy然后调用scipy.special.erf()将不起作用。