Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between np.float64 and np.double?

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'
like image 625
Jemshid KK Avatar asked Apr 28 '17 12:04

Jemshid KK


2 Answers

I think you're comparing apples with oranges.

The first bench is basically a * b but the second a * a.

I suspect much less cache misses for the latter.

like image 66
Cong Ma Avatar answered Sep 17 '22 18:09

Cong Ma


import numpy as np
np.double is np.float64 # returns True

In theory both should be same.

like image 27
3mpty Avatar answered Sep 17 '22 18:09

3mpty