Transforming a list to a column vector in Python

前端 未结 4 1982
面向向阳花
面向向阳花 2021-01-21 05:33

I was wondering if there\'s a function that takes a list X as input and outputs a column vector corresponding to X?

(I looked around and I susp

4条回答
  •  醉话见心
    2021-01-21 05:49

    similar but different:

    mylist=[2,3,4,5,6]
    

    method1:

    np.array([[i] for i in mylist])
    

    output:

    array([[2],
           [3],
           [4],
           [5],
           [6]])
    

    method 2:

    np.array(mylist).reshape(len(mylist),1)
    
    output:
        array([[2],
               [3],
               [4],
               [5],
               [6]])
    

提交回复
热议问题