【问题标题】:TypeError: unsupported operand type(s) for /: 'float' and 'csr_matrix'TypeError:不支持的操作数类型/:'float'和'csr_matrix'
【发布时间】:2018-10-30 16:39:17
【问题描述】:

我想写一个sigmoid函数:

def fn(w, x):
    return 1.0 / (np.expm1(-w.dot(x))+0.0)

因为 -w.dot(x) 是一个稀疏矩阵,所以我使用 np.expm1() 而不是 np.exp(),但是如何将浮点数除以 csr_matrix?谢谢!

【问题讨论】:

    标签: python numpy python-3.5 array-broadcasting


    【解决方案1】:
    from spicy import sparse 
    res2 = np.expm1(-w.dot(x)) 
    res1 = sparse.csr_matrix(np.ones(res2.shape()))
    return res1/res2
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-06
      • 2014-03-28
      • 2018-06-20
      • 2017-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多