ValueError using max and min function over 2 dimensional Numpy array

    import numpy as np

x = np.array([[1,2,3,4,5,6,7,8],[1,2,3,4,5,6,7,8]])
print("Mean is :")
print(x.mean())
print("axis wise Mean:")
print(np.mean(x,axis = 0))
print("Standard deviation is:"+str(np.std(x)))
print("Median is :"+str(np.median(x)))

#Error Generating code is below :
print("max and min : ")
print(str(max(x))+" "+str(min(x)))

Output
_Mean is :
4.5
axis wise Mean:
[1. 2. 3. 4. 5. 6. 7. 8.]
Standard deviation is:2.29128784747792
Median is :4.5
max and min :


ValueError Traceback (most recent call last)
in ()
11 #Error Generating code is below :
12 print("max and min : “)
—> 13 print(str(max(x))+” "+str(min(x)))

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

_

You can use max() and min() over linear arrays of numbers / strings only.
Here each element of 2 d array is linear array which cant be compared with other array directly.

1 Like