how to convert 2d list to 2d numpy array?

后端 未结 4 1219
醉酒成梦
醉酒成梦 2020-12-22 23:28

I have a 2D list something like

a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] 

and I want to convert it to a 2d numpy array. Can we do it without

4条回答
  •  死守一世寂寞
    2020-12-23 00:01

    just use following code

    c = np.matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
    matrix([[1, 2, 3],
        [4, 5, 6],
        [7, 8, 9]])
    

    Then it will give you

    you can check shape and dimension of matrix by using following code

    c.shape

    c.ndim

提交回复
热议问题