Is there a good way to find the rank of a matrix in a field of characteristic p>0?
<p>I need an efficient algorithm or a known way to determine <a href="https://en.wikipedia.org/wiki/Rank_(linear_algebra)" rel="nofollow">the mathematical rank</a> of a matrix A with coefficients in a field of positive characteristic. </p>

<p>For example, in the finite field of 5 elements I have the following matrix:</p>

<pre><code>import numpy
A=[[2,3],[3,2]]
print numpy.linalg.matrix_rank(A)
</code></pre>

<p>This method gives me the result of 2, but in characteristic 5 this matrix has rank 1 since <code>[2,3]+[3,2]=[0,0]</code>.</p>

<p>Numpy doesn't have built-in support for finite fields. The matrix <code>A</code> in your code is treated as a matrix of real numbers, and hence has rank 2. </p>

<p>If you really need to support finite fields with Numpy, you'll have to define your own data type along with the arithmetic operations yourself, as shown <a href="http://stackoverflow.com/questions/17044064/how-to-calculate-numpy-arrays-on-galois-field">here</a>. There are of course the concerns about proper error handling (like divide by zero).</p>

<p>Even then, many common routines will have to be rewritten to support your field data types. For example, from the <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.matrix_rank.html" rel="nofollow">numpy.linalg.matrix_rank</a> documentation, the routine uses Singular Value Decomposition (SVD), which is not well defined for finite fields, so you'll have to code the rank finding algorithm yourself.</p>

<p>As for the algorithm itself, you could try implementing plain old Gaussian Elimination along <a href="http://stackoverflow.com/questions/16254654/test-if-matrix-is-invertible-over-finite-field">these lines</a>, but this can be a pain in the neck and really slow, so you will likely be better off with other tools/packages like <strong>Sage</strong>.</p>

python numpy matrix