python中哈希是什么意思_在python中向量化特征哈希
您可以使用帶權重的bincount來執行您要求的操作:
>>> np.bincount(h,weights=x)
array([ 10., 5., 10., 10., 6.])
對于矩陣:
>>> import numpy as np
>>> a=np.random.randint(0,5,(50,50))
>>> rand=np.random.rand(5)
>>> rand
array([ 0.10899745, 0.35296303, 0.21127571, 0.56433924, 0.27895281])
>>> b=np.take(rand,a)
#Unfortunately you cannot do it like this:
>>> np.bincount(a,weights=b)
Traceback (most recent call last):
File "", line 1, in
ValueError: object too deep for desired array
#There we go:
>>> np.bincount(a.flat,weights=b.flat)
array([ 55.04371257, 172.59892108, 96.34172236, 297.40677707,
145.89232039])
這使用了花哨的索引來查看發生了什么:
>>> np.bincount(a.flat)
array([505, 489, 456, 527, 523])
>>> np.bincount(a.flat)*rand
array([ 55.04371257, 172.59892108, 96.34172236, 297.40677707,
145.89232039])
總結
以上是生活随笔為你收集整理的python中哈希是什么意思_在python中向量化特征哈希的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python多线程执行其他模块的文件_p
- 下一篇: qt定时连续发送udp数据包_TCP和U