How to create nested lists in python?

前端 未结 5 382
无人及你
无人及你 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 01:54

    In case a matrix is actually what you are looking for, consider the numpy package.

    http://docs.scipy.org/doc/numpy/reference/generated/numpy.zeros.html#numpy.zeros

    This will give you a 3x3x3 array of zeros:

    numpy.zeros((3,3,3)) 
    

    You also benefit from the convenience features of a module built for scientific computing.

提交回复
热议问题