TypeError:/:'float'和'csr_matrix'的不支持的操作数类型

时间:2021-11-12 21:23:00

I want to write a sigmoid function:

我想写一个sigmoid函数:

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

Because -w.dot(x) is a sparse matrix, I used np.expm1() instead of np.exp(), but how to divide a float by a csr_matrix? Thanks!

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

1 个解决方案

#1


0  

from spicy import sparse 
res2 = np.expm1(-w.dot(x)) 
res1 = sparse.csr_matrix(np.ones(res2.shape()))
return res1/res2

#1


0  

from spicy import sparse 
res2 = np.expm1(-w.dot(x)) 
res1 = sparse.csr_matrix(np.ones(res2.shape()))
return res1/res2