python中3d数组的最大值

Aja*_*man 2 python arrays numpy multidimensional-array

我想在python中找到3d数组的最大值.我试过了

image_file1 = open("lena256x256.bmp","rb")
img_i = PIL.Image.open(image_file1)
pix = numpy.array(img_i);
maxval= max(pix)
Run Code Online (Sandbox Code Playgroud)

但我收到一个错误

 File "test.py", line 31, in <module>
    maxval= max(pix)
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Run Code Online (Sandbox Code Playgroud)

我不能在这里弄错,请帮助我.

Jan*_*ila 5

您正在使用max不了解多维NumPy数组的内置函数.您必须使用以下之一:

在1D NumPy阵列的情况下,这些也比内置更快.