Python: Differentiating between row and column vectors

前端 未结 12 1537
不知归路
不知归路 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:36

    You can store the array's elements in a row or column as follows:

    >>> a = np.array([1, 2, 3])[:, None] # stores in rows
    >>> a
    array([[1],
           [2],
           [3]])
    
    >>> b = np.array([1, 2, 3])[None, :] # stores in columns
    >>> b
    array([[1, 2, 3]])
    

提交回复
热议问题