如果我想找到所有 3D 数组中最大值的坐标,如何找到它们?
到目前为止,这是我的代码,但它不起作用,我不明白为什么。
s = set()
elements = np.isnan(table)
numbers = table[~elements]
biggest = float(np.amax(numbers))
a = table.tolist()
for x in a:
coordnates = np.argwhere(table == x)
if x == biggest:
s.add((tuple(coordinates[0]))
print(s)
例如:
table = np.array([[[ 1, 2, 3],
[ 8, 4, 11]],
[[ 1, 4, 4],
[ 8, 5, 9]],
[[ 3, 8, 6],
[ 11, 9, 8]],
[[ 3, 7, 6],
[ 9, 3, 7]]])
应该返回s = {(0, 1, 2),(2, 1, 0)}