zoukankan      html  css  js  c++  java
  • TypeError: list indices must be integers or slices, not tuple

    由于dataset是一个列表

    >>> dataset
    [[1.658985, 4.285136], [-3.453687, 3.424321], [4.838138, -1.151539], [-5.379713, -3.362104], [0.972564, 2.924086], [-3.567919, 1.531611], [0.450614, -3.302219], [-3.487105, -1.724432], [2.668759, 1.594842], [-3.156485, 3.191137], [3.165506, -3.999838], [-2.786837, -3.099354], [4.208187, 2.984927], [-2.123337, 2.943366], [0.704199, -0.479481], [-0.39237, -3.963704], [2.831667, 1.574018], [-0.790153, 3.343144], [2.943496, -3.357075], [-3.195883, -2.283926], [2.336445, 2.875106], [-1.786345, 2.554248], [2.190101, -1.90602], [-3.403367, -2.778288], [1.778124, 3.880832], [-1.688346, 2.230267], [2.592976, -2.054368], [-4.007257, -3.207066], [2.257734, 3.387564], [-2.679011, 0.785119], [0.939512, -4.023563], [-3.674424, -2.261084], [2.046259, 2.735279], [-3.18947, 1.780269], [4.372646, -0.822248], [-2.579316, -3.497576], [1.889034, 5.1904], [-0.798747, 2
    所以获取第一列的时候就会出现这个问题

    >>> dataset[:,0]
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: list indices must be integers or slices, not tuple
    需要将之转为矩阵

    >>> dataset=mat(dataset)
    >>> dataset[:,0]
    matrix([[ 1.658985],
            [-3.453687],
            [ 4.838138],
            [-5.379713],
            [ 0.972564],
            [-3.567919],
            [ 0.450614],
            [-3.487105],
            [ 2.668759],
            [-3.156485],
            [ 3.165506],




    欢迎关注我的公众号:小秋的博客 CSDN博客:https://blog.csdn.net/xiaoqiu_cr github:https://github.com/crr121 联系邮箱:rongchen633@gmail.com 有什么问题可以给我留言噢~
  • 相关阅读:
    hadoop的namenode故障处理方法
    hadoop的checkpoint检查时间参数设置
    hadoop配置历史服务器&&配置日志聚集
    hadoop_批量命令脚本&同步文件脚本
    查看centos操作系统、java_jdk、hadoop位数
    hadoop的namenode启动失败
    shell_语法
    Mycat入门配置_读写分离配置
    VM虚拟机克隆_修改网络
    ssh免密登陆及时间设置
  • 原文地址:https://www.cnblogs.com/flyingcr/p/10326976.html
Copyright © 2011-2022 走看看