Iterating over arbitrary dimension of numpy.array

前端 未结 5 1595
生来不讨喜
生来不讨喜 2020-12-01 08:55

Is there function to get an iterator over an arbitrary dimension of a numpy array?

Iterating over the first dimension is easy...

In [63]: c = numpy.a         


        
5条回答
  •  星月不相逢
    2020-12-01 09:26

    You can use numpy.shape to get dimensions, and then range to iterate over them.

    n0, n1, n2 = numpy.shape(c)
    
    for r in range(n0):
        print(c[r,:,:])
    

提交回复
热议问题