np.trace

np.trace(x)[source]

Returns the sum along the diagonal of a Galois field array.

References

Examples

In [1]: GF = galois.GF(31)

In [2]: A = GF.Random((5,6)); A
Out[2]: 
GF([[ 5, 19,  6, 14, 26, 23],
    [22, 13,  1,  6, 16, 27],
    [11,  3,  5, 12,  4,  9],
    [ 0, 13,  5, 14,  4, 20],
    [ 6, 19,  3, 16, 12, 25]], order=31)

In [3]: np.trace(A)
Out[3]: GF(18, order=31)

In [4]: A[0,0] + A[1,1] + A[2,2] + A[3,3] + A[4,4]
Out[4]: GF(18, order=31)
In [5]: np.trace(A, offset=1)
Out[5]: GF(30, order=31)

In [6]: A[0,1] + A[1,2] + A[2,3] + A[3,4] + A[4,5]
Out[6]: GF(30, order=31)