为什么对于矩阵乘法而言,numpy和火炬要比R快得多?

时间:2019-06-11 11:04:47

标签: python r performance numpy torch

在Python中:

>>> import numpy as np
>>> x0=np.random.rand(3000,3000)
>>> t=time.perf_counter(); y0=np.matmul(x0,x0); time.perf_counter()-t
0.8358144999947399

>>> import torch
>>> x=torch.rand(3000,3000)
>>> t=time.perf_counter(); y0=np.matmul(x,x); time.perf_counter()-t
0.4304323000833392

在R中:

> a=matrix(runif(9000000), 3000, 3000)
> a1=a%*%a
> system.time({a1=a%*%a})
   user  system elapsed 
  16.53    0.04   16.57

为什么numpy和火炬的差异是20倍?

0 个答案:

没有答案