input: Write a function to calculate the average of the elements in a 2-dimensional array. If the given array is empty, return 0. The function should return the average of all elements in the array.
  assert averageMatrix([[3,2,6],[8,5,9],[4,7,1]])==5.0
  assert averageMatrix([[1,2],[3,4]])==2.5
  assert averageMatrix([[]])==0
  assert averageMatrix([[10,20],[30,40]])==25.0
  assert averageMatrix([])==0
output: def averageMatrix(arr):
      if not arr or not arr[0]:
          return 0
      total = 0
      count = 0
      for row in arr:
          for elem in row:
              total += elem
              count += 1
      return total / count