I am writing a simple loop to get the max value inside an array.
I know there is the function arr.max() but I'm just curious why the following code does not work.
import numpy as np
arr1 = np.arange(0,9).reshape(3,3)
max_value = arr1[0]
for i in arr1:
if max_value > i:
max_value = i
print(max_value)
which gives me:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last) <ipython-input-80-9fb1fcfa0948> in <module>
1 max_value = arr1[0]
2 for i in arr1:
----> 3 if i > max_value:
4 max_value = i
ValueError: The truth value of an array with more than one element is
ambiguous. Use a.any() or a.all()