np.float64和np.double有什么区别? [英] What is the difference between np.float64 and np.double?
本文介绍了np.float64和np.double有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试运行以下代码来找出numpy
中float64
和double
之间的区别.结果很有趣,因为double类型所花的时间几乎是与float64
相乘所花费的时间的两倍.需要一些启示.
I tried running the following code to find out the difference between float64
and double
in numpy
. The result is interesting as type double takes almost double the time compared with time taken for multiplication with float64
. Need some light on this.
import time
import numpy as np
datalen = 100000
times = 10000
a = np.random.rand(datalen)
b = np.random.rand(datalen)
da = np.float64(a)
db = np.float64(a)
dda = np.double(a)
ddb = np.double(b)
tic = time.time()
for k in range(times):
dd = dda * ddb
toc = time.time()
print (toc - tic), 'time taken for double'
tic = time.time()
for k in range(times):
d = da * db
toc = time.time()
print (toc - tic), 'time taken for float64'
推荐答案
我认为您正在将苹果与橙子进行比较.
I think you're comparing apples with oranges.
第一个席位基本上是a * b
,但第二个席位是a * a
.
The first bench is basically a * b
but the second a * a
.
我怀疑后者的缓存丢失要少得多.
I suspect much less cache misses for the latter.
这篇关于np.float64和np.double有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文