def indicatorsFromVector(vector, nCls=None, conf=1.0):
dtype = np.result_type(vector.dtype, np.float32)
if nCls is None:
nCls = np.max(vector)+1
labels = np.arange(nCls, dtype=dtype)
indicators = np.ones((len(vector), len(labels)), dtype=dtype)
indicators = ((indicators*vector[:,None]) == (indicators*labels))
offset = (1.0 - conf) / (nCls-1)
indicators = indicators * (conf-offset) + offset
return indicators.astype(dtype, copy=False)
评论列表
文章目录