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)