numpy初用

import numpy as np
for k,v in stat.iteritems():
    print k
    v.sort()
    #v = v[len(v)*3/100:len(v)*97/100]
    data = np.array(v)
    hist,bins=np.histogram(data,bins=np.linspace(data.min(),data.max(),20))
    #hist,bins=np.histogram(data,bins=20)
    print data.min(), data.max(), np.average(data)
    print hist
    print bins
    print v[0::len(v)/20]
 
with open('candidate_words') as f:
    for nline, line in enumerate(f):
        line = line.strip()
        terms = line.split(' ')
        query_vocab[''.join(terms)] = nline
 
        vecs = [vec_space[term] for term in terms if term in vec_space]
        weights = [term_imp_dict.get(term, 0.0) for term in terms if term in vec_space]
        #if len(vecs) == 1:
        #    terms_vec = vecs[0]
        #else:
        #    terms_vec = [sum(x) for x in izip(*vecs)]
        #terms_vec = [elem/len(terms_vec) for elem in terms_vec]
        if not vecs:
            continue
        if max(weights) == 0:
            continue
        vecs = np.array(vecs)
        terms_vec = np.average(vecs, axis=0, weights=weights)
        terms_vec_len = np.linalg.norm(terms_vec)
        ters_vec = terms_vec / terms_vec_len
        aindex.add_item(nline, terms_vec.tolist())

转载于:https://www.cnblogs.com/yaoyaohust/p/10363180.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值