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

后端 未结 4 1218
醉酒成梦
醉酒成梦 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条回答
  •  旧时难觅i
    2020-12-23 00:13

    np.array() is even more powerful than what unutbu said above. You also could use it to convert a list of np arrays to a higher dimention array, the following is a simple example:

    aArray=np.array([1,1,1])
    
    bArray=np.array([2,2,2])
    
    aList=[aArray, bArray]
    
    xArray=np.array(aList)
    

    xArray's shape is (2,3), it's a standard np array. This operation avoids a loop programming.

提交回复
热议问题