【问题标题】:Can somebody explain me what is the role of two indices of array instead of single index of array?有人可以解释一下数组的两个索引而不是数组的单个索引的作用吗?
【发布时间】:2020-12-27 09:44:00
【问题描述】:

为什么我在使用h[0,0] 时会出错。还有,h[[0,0]]的目的是什么?

【问题讨论】:

    标签: arrays python-3.x numpy


    【解决方案1】:

    h[[0, 0]] 中为您提供第 0 位和第 0 位,因此,

    print(h[[0, 0]])
    # [0, 0]
    h[[0, 0]] = [4, 6]
    # Equivalent would be 
    h[0] = 4
    h[6] = 6
    

    虽然h[0, 0] 会引发IndexError,因为h 在这里是一维数组。如果它是一个二维数组,那么它将为您提供第 0 行和第 0 列值的输出。

    【讨论】:

      猜你喜欢
      • 2014-01-13
      • 1970-01-01
      • 2015-01-13
      • 2020-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多