【问题标题】:How do I append rows to an array in Python?如何在 Python 中将行追加到数组中?
【发布时间】:2016-03-04 00:20:21
【问题描述】:

我有一个 1X3 矩阵的数组,其中: 第 1 列 = x 坐标 第 2 列 = y 坐标 第 3 列 = 向量的方向。

我正在沿着一条路径跟踪一系列点。 在每一点,我都想将 x、y 和方向作为一行存储回数组中。

所以最后,我的数组垂直增长,代表路径上的点的行越来越多。

我正在努力在一个类中构建这个函数。 请帮忙?

Xx

【问题讨论】:

标签: python arrays list matrix append


【解决方案1】:

您正在寻找append 函数。但是你应该认真看看numpy 在 python 中使用矩阵

【讨论】:

    【解决方案2】:

    使用.append('item-goes-here') 追加。

    【讨论】:

      【解决方案3】:
      In [1]: x = [1,2]
      
      In [2]: y = [3,4]
      
      In [3]: x+y
      Out[3]: [1, 2, 3, 4]
      

      【讨论】:

        【解决方案4】:
        # This is your matrix 1x3
        matrix = []
        
        # Use a list to store (x, y, direction)
        data = [x, y, direction]
        
        # To add data to the matrix use `append` on matrix list
        matrix.append(point)
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2021-08-20
          • 1970-01-01
          • 1970-01-01
          • 2020-09-21
          • 2015-02-21
          • 2022-01-25
          • 1970-01-01
          相关资源
          最近更新 更多