小编Pak*_*ong的帖子

为什么要根据速度使用 numpy over list?

参考为什么使用 NumPy 而不是 Python 列表?

tom10 说:

速度:这是对列表和 NumPy 数组进行求和的测试,表明 NumPy 数组上的求和速度快 10 倍(在此测试中——里程可能会有所不同)。

但我的测试使用以下代码:

import numpy as np
import time as time

N = 100000

#using numpy
start = time.time()
array = np.array([])

for i in range(N):
    array = np.append(array, i)

end = time.time()
print ("Using numpy: ", round(end-start, 2), end="\n")

#using list
start = time.time()
list = []

for i in range(N):
    list.append(i)

list = np.array(list)   
end = time.time()
print ("Using list : ", round(end-start, 2), end="\n") …
Run Code Online (Sandbox Code Playgroud)

python arrays numpy

5
推荐指数
1
解决办法
4737
查看次数

标签 统计

arrays ×1

numpy ×1

python ×1