title: Numpy matrix determinant precision problems
body: <p>I am trying to write a script on python to determine a matrix determinant using Gauss method. It works correctly, but the precision isn't enough for me.
  My code is:</p>
  
  <pre><code>import scipy.linalg as sla
  import numpy as np
  def my_det(X):
      n = len(X)
      s = 0
      if n != len(X[0]):
          return ValueError
      for i in range(0, n):
          maxElement = abs(X[i][i])
          maxRow = i
          for k in range(i+1, n):
              if abs(X[k][i]) &gt; maxElement:
                  maxElement = abs(X[k][i])
                  maxRow = k
          if maxRow != i:
              s += 1
          for k in range(i, n):
              X[i][k], X[maxRow][k] = X[maxRow][k], X[i][k]
          for k in range(i+1, n):
              c = -X[k][i]/X[i][i]
              for j in range(i, n):
                  if i == j:
                      X[k][j] = 0
                  else:
                      X[k][j] += c * X[i][j]
      det = (-1)**s
      for i in range(n):
          det *= X[i][i]
      return det
  </code></pre>
  
  <p>And I have tests for this code:</p>
  
  <pre><code>for x in range(10):
  X = np.random.rand(3,3)
  if np.abs(my_det(X) - sla.det(X)) &gt; 1e-6:
      print('FAILED')
  </code></pre>
  
  <p>My function fails all tests. I tried Decimals, but it didn't help.
  What's wrong?</p>