其他分享
首页 > 其他分享> > np.bincout()详解

np.bincout()详解

作者:互联网

参考:numpy.bincount详解_踩风火轮的乌龟-CSDN博客_np.bincount
np.bincount(x,weights,minlength),

x为指定数组,weights是生成bin后每一个元素的权重,minlength是bin的最大长度,不指定的情况下为默认的x中的最大值。

out[n] += weight[i]

# x中最大的数为7,bin的数量为8,那么它的索引值为0-7
x = np.array([0, 1, 1, 3, 2, 1, 7])
# 0出现了1次,1出现了3次...5出现了0次
np.bincount(x)
# 结果:array([1, 3, 1, 1, 0, 0, 0, 1])
w = np.array([0.3, 0.5, 0.2, 0.7, 1., -0.6])
x = np.array([2, 1, 3, 4, 4, 3])

# 索引0-0
# 索引1所在位置的权重: w[1] = 0.5
# 索引2所在x中对应位置的权重; w[0] = 0.3
# 索引3  w[2] + w[5] = 0.2 - 0.6 = -0.4
# 索引4  w[3] + w[4] = 0.7 + 1 = 1.7

np.bincount(x,  weights=w)
#结果:array([ 0. ,  0.5,  0.3, -0.4,  1.7])

标签:bin,bincout,bincount,0.3,索引,详解,np,array
来源: https://blog.csdn.net/laner__gg/article/details/120412554