How to create nested lists in python?

前端 未结 5 428
无人及你
无人及你 2021-01-13 01:14

I know you can create easily nested lists in python like this:

[[1,2],[3,4]]

But how to create a 3x3x3 matrix of zeroes?

[[         


        
5条回答
  •  青春惊慌失措
    2021-01-13 02:08

    List comprehensions are just syntactic sugar for adding expressiveness to list initialization; in your case, I would not use them at all, and go for a simple nested loop.

    On a completely different level: do you think the n-dimensional array of NumPy could be a better approach?
    Although you can use lists to implement multi-dimensional matrices, I think they are not the best tool for that goal.

提交回复
热议问题