Creating a 2d matrix in python

后端 未结 3 818
粉色の甜心
粉色の甜心 2020-12-06 15:57

I create a 6x5 2d array, initially with just None in each cell. I then read a file and replace the Nones with data as I read them. I create the empty array first because the

3条回答
  •  无人及你
    2020-12-06 16:45

    If you aren't going the numpy route, you can fake 2D arrays with dictionaries:

    >>> x = dict( ((i,j),None) for i in range(5) for j in range(6) )
    >>> print x[3,4]
    None
    

提交回复
热议问题