Converting a 3D List to a 3D NumPy array

前端 未结 5 1042
北海茫月
北海茫月 2021-01-18 16:19

Currently, I have a 3D Python list in jagged array format.
A = [[[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[0], [0], [0]]]

Is there any way I could convert

5条回答
  •  遥遥无期
    2021-01-18 16:50

    Looping and adding is likely better, since you want to preserve the structure of the original. Plus, the error you mentioned indicates that you would need to flatten the numpy array and then add to each element. Although numpy operations tend to be faster than list operations, converting, flattening, and reverting is cumbersome and will probably offset any gains.

提交回复
热议问题