Max value of a 3d array in python
21,528
Solution 1
You are using the builtin max
function that does not understand multidimensional NumPy arrays. You must instead use one of:
pix.max()
numpy.max(pix)
numpy.amax(pix)
These are also faster than the builtin in the case of 1D NumPy arrays.
Solution 2
Max is expecting a single value, the error message should be quite clear, you want to use amax
instead.
maxval = numpy.amax(pix)
Comments
-
Ajay Soman about 4 years
I want to find the max value of a 3d array in python. I tried
image_file1 = open("lena256x256.bmp","rb") img_i = PIL.Image.open(image_file1) pix = numpy.array(img_i); maxval= max(pix)
but i am getting an error
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()
I cannot catch my mistake here, please help me.