小编yk4*_*4r2的帖子

极地 arr.get(i) 替换

我有一个代码

df.select([
    pl.all().exclude("elapsed_time_linreg"),
    pl.col("elapsed_time_linreg").arr.get(0).suffix("_slope"),
    pl.col("elapsed_time_linreg").arr.get(1).suffix("_intercept"),
    pl.col("elapsed_time_linreg").arr.get(2).suffix("_resid_std"),
])
Run Code Online (Sandbox Code Playgroud)

解压函数的结果

@jit
def linear_regression(session_np: np.ndarray) -> np.ndarray:
    w = len(session_np)
    x = np.arange(w)
    sx = w ** 2 / 2
    sy = np.sum(session_np)
    sx2 = (w * (w + 1) * (2 * w + 1)) / 6
    sxy = np.sum(x * session_np)
    slope = (w * sxy - sx * sy) / (w * sx2 - sx**2)
    intercept = (sy - slope * sx) / w
    resids = session_np - (x * …
Run Code Online (Sandbox Code Playgroud)

python numpy python-polars

3
推荐指数
1
解决办法
545
查看次数

标签 统计

numpy ×1

python ×1

python-polars ×1