【问题标题】:python memory error when trying make the dot product between 2 arrays尝试在2个数组之间进行点积时出现python内存错误
【发布时间】:2018-04-30 13:26:09
【问题描述】:

我正在尝试使用softmax的导数https://medium.com/@aerinykim/how-to-implement-the-softmax-derivative-independently-from-any-loss-function-ae6d44363a9d

这是我使用的功能:

def softmax_grad(softmax):
    s = softmax.reshape(-1,1)
    return np.diagflat(s) - np.dot(s, s.T)

当我调用它时,我得到了这个错误

<ipython-input-72-4aed1c61658a> in softmax_prime(x)
      6 
      7     s = x.reshape(-1,1)
----> 8     return np.diagflat(s) - np.dot(s, s.T)

D:\anaconda\lib\site-packages\numpy\lib\twodim_base.py in diagflat(v, k)
    306     s = len(v)
    307     n = s + abs(k)
--> 308     res = zeros((n, n), v.dtype)
    309     if (k >= 0):
    310         i = arange(0, n-k)

MemoryError: 

是因为尺寸吗?我作为参数传递的数组大小为 (100, 60000),点积在形状 (600000, 1) 之间 (1, 600000)

【问题讨论】:

    标签: python arrays numpy memory softmax


    【解决方案1】:

    这将产生一个大小为 (600000, 600000) 的数组,我假设它不适合您的工作内存。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-06
      • 2018-10-21
      • 1970-01-01
      • 2021-02-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多