zoukankan      html  css  js  c++  java
  • IndexError: tuple index out of range

    错误代码:

    def loadDataSet(fileName):      #general function to parse tab -delimited floats
        dataMat = []                #assume last column is target value
        fr = open(fileName)
        for line in fr.readlines():
            curLine = line.strip().split('	')
            fltLine = map(float,curLine) #map all elements to float()
            dataMat.append(fltLine)
        return dataMat

    打印出dataset

    [<map object at 0x0000022920841B70>, <map object at 0x0000022920841C50>, <map object at 0x0000022920841D68>, 。。。。。。

    发现是一个个map对象

     shape(dataset)
    (80,)
    只有行数没有列数

    代码修正:

    def loadDataSet(fileName):      #general function to parse tab -delimited floats
        dataMat = []                #assume last column is target value
        fr = open(fileName)
        for line in fr.readlines():
            curLine = line.strip().split('	')
            fltLine = list(map(float,curLine)) #map all elements to float()//将map对象转为list列表
            dataMat.append(fltLine)
        return dataMat
    shape(dataset)
    (80, 2)




    欢迎关注我的公众号:小秋的博客 CSDN博客:https://blog.csdn.net/xiaoqiu_cr github:https://github.com/crr121 联系邮箱:rongchen633@gmail.com 有什么问题可以给我留言噢~
  • 相关阅读:
    pytesser模块WindowsError错误解决方法
    Django 1.10中文文档-聚合
    Django 1.10中文文档-执行查询
    Python NLP入门教程
    Django1.10中文文档—模型
    曲线点抽稀算法-Python实现
    Python判断文件是否存在的三种方法
    epoll原理
    多线程编程
    后端知识地图
  • 原文地址:https://www.cnblogs.com/flyingcr/p/10326978.html
Copyright © 2011-2022 走看看