title: Trouble with multiplying matrices
body: <p>I am trying to do some QR decomposition for an optional assignment and I am not using numpy:</p>
  
  <pre><code>def multiply(matrix1, matrix2):
      rows_A = len(matrix1)
      cols_A = len(matrix1[0])
      rows_B = len(matrix2)
      cols_B = len(matrix2[0])
  
      new_matrix = [[0 for row in range(cols_B)] for col in range(rows_A)]
  
      for i in range(len(matrix1)):
          for j in range(len(matrix2[0])):
              for k in range(len(matrix2)):
                  new_matrix[i][j] += matrix1[i][k]*matrix2[k][j]
      return new_matrix
  
  def transpose(matrix):
      newmatrix = []
      for i in range(len(matrix)):
          newline = []
          for j in range(len(matrix[i])):
              newline.append(matrix[j][i])
          newmatrix.append(newline)
      for k in range(len(newmatrix)):
          print(newmatrix[k])
      return matrix
  
  # Returns the Gramm-Schmidt orthogonalization of matrix X
  def gramm_schmidt(X, inplace = False):
      if not inplace:
         V = [row[:] for row in X]  # make a copy.
      else:
         V = X
      k = len(X[0])          # number of columns. 
      n = len(X)             # number of rows.
  
      for j in range(k):
         for i in range(j):
            # D = &lt; Vi, Vj&gt;
            D = sum([V[p][i]*V[p][j] for p in range(n)])
  
            for p in range(n): 
              # Note that the Vi's already have length one!
              # Vj = Vj - &lt;Vi,Vj&gt; Vi/&lt; Vi,Vi &gt;
              V[p][j] -= (D * V[p][i])
  
         # Normalize column V[j]
         invnorm = 1.0 / sqrt(sum([(V[p][j])**2 for p in range(n)]))
         for p in range(n):
             V[p][j] *= invnorm
      return V
  
  def QR(matrix):
      Q = gramm_schmidt(matrix)
      Q_transpose = transpose(Q)
      R = multiply(Q_transpose, matrix)
      QR = multiply(Q, R)
  
      print ("Q:\n")
      for row in Q:
          print (row)
      print ("\n")
  
      print ("R:\n")
      for row in R:
          print (row)
      print ("\n")
  
      print ("QR:\n")
      for row in QR:
          print (row)
      print ("\n")
  </code></pre>
  
  <p>But at this line in my code: </p>
  
  <pre><code>R = multiply(Q_transpose, matrix)
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>    rows_A = len(matrix1)
  TypeError: object of type 'NoneType' has no len()
  </code></pre>
  
  <p>And I'm not sure why because the multiply function itself works for when I do standard multiplication...thanks in advance if anyone can help!</p>
  
  <p>EDIT: I added a return statement to transpose, and yes it does actually give a transposed matrix. It seems the multiply is the culprit. Here is what it should do:</p>
  
  <pre><code> A:
          [[12, -51, 4],
          [6, 167, -68], 
          [-4, 24, -41]]
  Q:
      [[0.8571428571428571, 0.39428571428571435, -0.33142857142857135],
       [0.4285714285714286, -0.9028571428571429, 0.034285714285714114],
       [-0.28571428571428575, -0.17142857142857126, -0.942857142857143]]
  R:
      [[13.999999999999998, 21.00000000000001, -14.000000000000004],
       [-5.506706202140776e-16, -175.00000000000003, 70.0],
       [3.0198066269804245e-16, -3.552713678800501e-14, 35.000000000000014]]
  </code></pre>
  
  <p>but I only get Q to work properly.</p>