【发布时间】:2020-07-14 13:06:48
【问题描述】:
所以,我只是想让这更快:
for x in range(matrix.shape[0]):
for y in range(matrix.shape[1]):
if matrix[x][y] == 2 or matrix[x][y] == 3 or matrix[x][y] == 4 or matrix[x][y] == 5 or matrix[x][y] == 6:
if x not in heights:
heights.append(x)
只需遍历一个 2x2 矩阵(通常为 18x18 或 22x22 圆形)并检查它是否为 x。但它有点慢,我想知道哪种方法最快。
非常感谢!
【问题讨论】:
标签: python python-3.x numpy multidimensional-array numpy-ndarray