Produce a Python code section to calculate the average value for all elements of a given array.
[2, 7, 5, 4]
array = [2, 7, 5, 4]

total = 0
for num in array:
 total += num
average = total/len(array)

print("The average of the array is:", average)