Python: Differentiating between row and column vectors

前端 未结 12 1543
不知归路
不知归路 2020-12-07 08:56

Is there a good way of differentiating between row and column vectors in python? So far I\'m using numpy and scipy and what I see so far is that If I was to give one a vecto

12条回答
  •  暖寄归人
    2020-12-07 09:21

    Here's another intuitive way. Suppose we have:

    >>> a = np.array([1, 3, 4])
    >>> a
    array([1, 3, 4])
    

    First we make a 2D array with that as the only row:

    >>> a = np.array([a])
    >>> a
    array([[1, 3, 4]])
    

    Then we can transpose it:

    >>> a.T
    array([[1],
           [3],
           [4]])
    

提交回复
热议问题