魂杖道长 2017-08-31 16:25 采纳率: 0%
浏览 7301

'float' object cannot be interpreted as an integer

在运行代码的时候调用了zeros函数,按理说里面的dtype参数默认也应该是float啊,可是不知道为什么会报错,代码如下:

def _load_representation(self):
    '''
        load user and item latent features generate by MF for every meta-graph
    '''
    #if dt in ['yelp-200k', 'amazon-200k', 'amazon-50k', 'amazon-100k', 'amazon-10k', 'amazon-5k', 'cikm-yelp', 'yelp-50k', 'yelp-10k', 'yelp-5k', 'yelp-100k', 'douban']:
    fnum = self.N / 2
    ufilename = self.data_dir + 'uids.txt'
    bfilename = self.data_dir + 'bids.txt'
    uids = [int(l.strip()) for l in open(ufilename, 'r').readlines()]
    uid2reps = {k:np.zeros(fnum, dtype=np.float64) for k in uids}
    bids = [int(l.strip()) for l in open(bfilename, 'r').readlines()]
    bid2reps = {k:np.zeros(fnum, dtype=np.float64) for k in bids}

    ufiles, vfiles = self._generate_feature_files()

    feature_dir = self.data_dir + 'mf_features/path_count/'
    for find, filename in enumerate(ufiles):
        ufs = np.loadtxt(feature_dir + filename, dtype=np.float64)
        cur = find * self.F
        for uf in ufs:
            uid = int(uf[0])
            f = uf[1:]
            uid2reps[uid][cur:cur+self.F] = f

    for find, filename in enumerate(vfiles):
        bfs = np.loadtxt(feature_dir + filename, dtype=np.float64)
        cur = find * self.F
        for bf in bfs:
            bid = int(bf[0])
            f = bf[1:]
            bid2reps[bid][cur:cur+self.F] = f
    logging.info('load all representations, len(ufiles)=%s, len(vfiles)=%s, ufiles=%s, vfiles=%s', len(ufiles), len(vfiles), '|'.join(ufiles), '|'.join(vfiles))
    return uid2reps, bid2reps

有问题的应该是里面这两句:

uids = [int(l.strip()) for l in open(ufilename, 'r').readlines()]
uid2reps = {k:np.zeros(fnum, dtype=np.float64) for k in uids}

最前面有导入numpy“import numpy as np”,求大神帮忙看看到底是哪里错了。。一直会提示“TypeError: 'float' object cannot be interpreted as an integer”。。

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-09-09 18:34
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 以帮助更多的人 ^-^
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog