当前位置: 动力学知识库 > 问答 > 编程问答 >

python - NumPy log function throws attribute error for int

问题描述:

I am trying to use a log loss function and keep getting the following error-

 AttributeError: log

the line of code that is throwing this error is -

ll = sum(act*sp.log(pred) + sp.subtract(1,act)*sp.log(sp.subtract(1,pred)))

where pred is-

[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0......1]

and act is-

[[0 1]

[1 1]

[2 1]

[3 1]

[4 1]

[5 1]

[6 1]

[7 1]

[8 1]

[9 1]

.

.

.

[n 1]]

Can someone help me with this? Completely driven up the wall.

网友答案:

@WarrenWeckesser's answer helped me-

"As a work-around, replace pred with pred.astype(int) (or pred.astype(float) if the values are floating point) in your expression for ll"

分享给朋友:
您可能感兴趣的文章:
随机阅读: