在 Python 中遍历多维数组 [英] Iterating through a multidimensional array in Python

查看:85
本文介绍了在 Python 中遍历多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Python 中创建了一个多维数组,如下所示:

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 elements of my twodimensional array, and I do not care about the order. How do I achieve this?

推荐答案

很明显你在使用 numpy.使用 numpy 你可以这样做:

It's clear you're using numpy. With numpy you can just do:

for cell in self.cells.flat:
    do_somethin(cell)

这篇关于在 Python 中遍历多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆