scipy.interpolate.LinearNDInterpolator 在 Docker 容器中运行会填满内存

问题描述 投票:0回答:1

为什么当我直接在计算机上运行它并且几乎不使用任何 RAM 时,它会在 3 秒内运行,但当我在 Python Docker 容器中运行它时,会填满 30GB RAM20GB 交换空间

测试.py

import time
import numpy as np
from scipy.interpolate import LinearNDInterpolator

start_time = time.time()
points = [(0, 1500), (0, 1800), (0, 2000), (0, 2200), (180, 1600), (180, 1900), (180, 2100), (180, 2300)]
values = [5, 20, 25, 40, 2, 10, 15, 20]
points = np.array(points, dtype=np.float64)
values = np.array(values, dtype=np.float64)
interp = LinearNDInterpolator(points, values)
rng = np.random.default_rng()
sampled_angles = 180 * rng.random(size=6000*6000, dtype=np.float64)
sampled_altitude = (2200 - 1600) * rng.random(size=6000*6000, dtype=np.float64) + 1600
interpolated_thicknesses = interp(sampled_angles, sampled_altitude)
print(interpolated_thicknesses[:10])
end_time = time.time()
elapsed_time = end_time - start_time
print(elapsed_time)

Dockerfile

FROM python

WORKDIR /calculator

COPY ./test.py ./test.py
COPY ./requirements.txt ./requirements.txt

RUN apt-get update
RUN apt-get install -y pip
RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt

CMD ["python3", "test.py"]

需求.txt

scipy
numpy
python docker numpy scipy
1个回答
0
投票

为 Python、SciPy 和 NumPy 选择这些版本可以解决该问题。我有兴趣知道:如果我自己的机器上没有运行该脚本,我如何知道要使用的正确版本?

Dockerfile

FROM python:3.10.12

需求.txt

scipy==1.8.0
numpy==1.21.5
© www.soinside.com 2019 - 2024. All rights reserved.