Generate a function in Python to determine the largest element in an array.
[3, 2, 1, 4, 5]
def find_max(arr):
 max_val = arr[0]
 for num in arr:
 if num > max_val:
 max_val = num
 return max_val

array = [3, 2, 1, 4, 5]
print(find_max(array))