我有这个函数:
import numpy as np
def unhot(vec):
""" takes a one-hot vector and returns the corresponding integer """
assert np.sum(vec) == 1 # this assertion shouldn't fail, but it did...
return list(vec).index(1)我在调用的输出上调用:
numpy.random.multinomial(1, coe)当我运行它的时候,我得到了一个断言错误。这怎麽可能?难道不能保证numpy.random.multinomial的输出是一个热点向量吗?
然后我删除了断言错误,现在我有了:
ValueError: 1 is not in list我是遗漏了什么小字,还是这本书坏了?
发布于 2014-04-25 00:46:01
嗯,这就是问题所在,我应该意识到,因为我以前遇到过:
np.random.multinomial(1,A([ 0., 0., np.nan, 0.]))返回
array([0, 0, -9223372036854775807,0])我使用的是一个不稳定的softmax实现,它提供了Nans。现在,我试图确保传递给多项式的参数有一个和<= 1,但我是这样做的:
coe = softmax(coeffs)
while np.sum(coe) > 1-1e-9:
coe /= (1+1e-5)有了NaNs,while语句甚至永远不会被触发,我想。
https://stackoverflow.com/questions/23257855
复制相似问题