title: matrix region sum function
body: <p>I'm having trouble understanding this piece of code. This function determines the sum of a selected area in a matrix. You are given matrix and coordinates of the top left(A) and bottom right(D) corner of the rectangle.</p>
  
  <pre><code>    def matrixRegionSum(matrix, A, D):
        if len(matrix) == 0:
          return
        totalSum = 0
        for i in range(A[0], D[0] + 1):
          for j in range (A[1], D[1] + 1):
            totalSum += matrix[i][j]
        return totalSum
  </code></pre>
  
  <p>The part I am stuck on is inside the range() function. I'm not sure how A[0], B[0], A[1], and B[1] access the matrix. Could someone explain? I see A[0] as the first value in an array, but a matrix is 2D. Could someone explain to me the logic behind this function? </p>
  
  <p>Thank you for the help! much appreciated!</p>