Iterating through a multidimensional array in Python

前端 未结 7 1522
旧巷少年郎
旧巷少年郎 2020-12-13 13:35

I have created a multidimensional array in Python like this:

self.cells = np.empty((r,c),dtype=np.object)

Now I want to iterate through all

7条回答
  •  忘掉有多难
    2020-12-13 14:15

    If you need to change the values of the individual cells then ndenumerate (in numpy) is your friend. Even if you don't it probably still is!

    for index,value in ndenumerate( self.cells ):
        do_something( value )
        self.cells[index] = new_value
    

提交回复
热议问题