input: Write a function to calculate the average of the elements in a 2-dimensional array. The function should iterate through each element in the array, sum them up, and then return the average value. If the array is empty, it should return 0.
  
  a = [[3,2,6],
       [8,5,9],
       [4,7,1]]
  
  assert averageMatrix(a) == 4.77
output: def averageMatrix(arr):
      if not arr:
          return 0
      total_sum = 0
      count = 0
      for row in arr:
          for elem in row:
              total_sum += elem
              count += 1
      return total_sum / count