np¶
Documentation of some native numpy functions when called on Galois field arrays.
General
|
Returns a copy of a given Galois field array. |
|
Concatenates the input arrays along the given axis. |
|
Inserts values along the given axis. |
Arithmetic
|
Adds two Galois field arrays element-wise. |
|
Subtracts two Galois field arrays element-wise. |
|
Multiplies two Galois field arrays element-wise. |
|
Divides two Galois field arrays element-wise. |
|
Returns the element-wise additive inverse of a Galois field array. |
Returns the element-wise multiplicative inverse of a Galois field array. |
|
|
Exponentiates a Galois field array element-wise. |
|
Squares a Galois field array element-wise. |
|
Computes the logarithm (base |
|
Computes the matrix multiplication of two Galois field arrays. |
Linear Algebra
|
Returns the sum along the diagonal of a Galois field array. |
|
Computes the matrix multiplication of two Galois field arrays. |
Returns the rank of a Galois field matrix. |
|
Raises a square Galois field matrix to an integer power. |
|
Computes the determinant of the matrix. |
|
Computes the inverse of the matrix. |
|
Solves the system of linear equations. |
- np.add(x, y)[source]¶
Adds two Galois field arrays element-wise.
References
Examples
In [1]: GF = galois.GF(31) In [2]: x = GF.Random(10); x Out[2]: GF([25, 23, 29, 14, 16, 10, 17, 4, 27, 13], order=31) In [3]: y = GF.Random(10); y Out[3]: GF([28, 4, 15, 6, 6, 26, 26, 6, 24, 30], order=31) In [4]: np.add(x, y) Out[4]: GF([22, 27, 13, 20, 22, 5, 12, 10, 20, 12], order=31) In [5]: x + y Out[5]: GF([22, 27, 13, 20, 22, 5, 12, 10, 20, 12], order=31)
- np.concatenate(arrays, axis=0)[source]¶
Concatenates the input arrays along the given axis.
See: https://numpy.org/doc/stable/reference/generated/numpy.concatenate.html
Examples
In [1]: GF = galois.GF(2**3) In [2]: A = GF.Random((2,2)); A Out[2]: GF([[4, 5], [3, 7]], order=2^3) In [3]: B = GF.Random((2,2)); B Out[3]: GF([[1, 0], [5, 5]], order=2^3) In [4]: np.concatenate((A,B), axis=0) Out[4]: GF([[4, 5], [3, 7], [1, 0], [5, 5]], order=2^3) In [5]: np.concatenate((A,B), axis=1) Out[5]: GF([[4, 5, 1, 0], [3, 7, 5, 5]], order=2^3)
- np.divide(x, y)[source]¶
Divides two Galois field arrays element-wise.
References
Examples
In [1]: GF = galois.GF(31) In [2]: x = GF.Random(10); x Out[2]: GF([10, 29, 19, 30, 28, 16, 0, 18, 1, 0], order=31) In [3]: y = GF.Random(10, low=1); y Out[3]: GF([30, 30, 27, 1, 6, 9, 30, 25, 1, 19], order=31) In [4]: z = np.divide(x, y); z Out[4]: GF([21, 2, 3, 30, 15, 19, 0, 28, 1, 0], order=31) In [5]: y * z Out[5]: GF([10, 29, 19, 30, 28, 16, 0, 18, 1, 0], order=31)
In [6]: np.true_divide(x, y) Out[6]: GF([21, 2, 3, 30, 15, 19, 0, 28, 1, 0], order=31) In [7]: x / y Out[7]: GF([21, 2, 3, 30, 15, 19, 0, 28, 1, 0], order=31) In [8]: np.floor_divide(x, y) Out[8]: GF([21, 2, 3, 30, 15, 19, 0, 28, 1, 0], order=31) In [9]: x // y Out[9]: GF([21, 2, 3, 30, 15, 19, 0, 28, 1, 0], order=31)
- np.insert(array, object, values, axis=None)[source]¶
Inserts values along the given axis.
See: https://numpy.org/doc/stable/reference/generated/numpy.insert.html
Examples
In [1]: GF = galois.GF(2**3) In [2]: x = GF.Random(5); x Out[2]: GF([7, 2, 7, 2, 5], order=2^3) In [3]: np.insert(x, 1, [0,1,2,3]) Out[3]: GF([7, 0, 1, 2, 3, 2, 7, 2, 5], order=2^3)
- np.log(x)[source]¶
Computes the logarithm (base
GF.primitive_element
) of a Galois field array element-wise.Calling
np.log()
implicitly uses basegalois.GFMeta.primitive_element
. Seegalois.GFArray.log()
for logarithm with arbitrary base.References
Examples
In [1]: GF = galois.GF(31) In [2]: alpha = GF.primitive_element; alpha Out[2]: GF(3, order=31) In [3]: x = GF.Random(10, low=1); x Out[3]: GF([14, 6, 27, 24, 3, 26, 9, 2, 5, 2], order=31) In [4]: y = np.log(x); y Out[4]: array([22, 25, 3, 13, 1, 5, 2, 24, 20, 24]) In [5]: alpha ** y Out[5]: GF([14, 6, 27, 24, 3, 26, 9, 2, 5, 2], order=31)
- np.matmul(x1, x2)[source]¶
Computes the matrix multiplication of two Galois field arrays.
References
Examples
In [1]: GF = galois.GF(31) In [2]: x1 = GF.Random((3,4)); x1 Out[2]: GF([[19, 16, 14, 25], [26, 3, 11, 14], [22, 8, 12, 27]], order=31) In [3]: x2 = GF.Random((4,5)); x2 Out[3]: GF([[14, 4, 19, 18, 18], [13, 13, 18, 1, 2], [ 7, 1, 21, 26, 8], [21, 21, 4, 11, 13]], order=31) In [4]: np.matmul(x1, x2) Out[4]: GF([[12, 17, 20, 5, 5], [30, 14, 29, 12, 0], [ 9, 27, 23, 21, 22]], order=31) In [5]: x1 @ x2 Out[5]: GF([[12, 17, 20, 5, 5], [30, 14, 29, 12, 0], [ 9, 27, 23, 21, 22]], order=31)
- np.multiply(x, y)[source]¶
Multiplies two Galois field arrays element-wise.
References
Examples
Multiplying two Galois field arrays results in field multiplication.
In [1]: GF = galois.GF(31) In [2]: x = GF.Random(10); x Out[2]: GF([17, 26, 6, 17, 12, 4, 24, 9, 15, 16], order=31) In [3]: y = GF.Random(10); y Out[3]: GF([ 7, 27, 15, 25, 16, 22, 15, 2, 6, 3], order=31) In [4]: np.multiply(x, y) Out[4]: GF([26, 20, 28, 22, 6, 26, 19, 18, 28, 17], order=31) In [5]: x * y Out[5]: GF([26, 20, 28, 22, 6, 26, 19, 18, 28, 17], order=31)
Multiplying a Galois field array with an integer results in scalar multiplication.
In [6]: GF = galois.GF(31) In [7]: x = GF.Random(10); x Out[7]: GF([ 8, 7, 27, 0, 20, 6, 5, 11, 17, 8], order=31) In [8]: np.multiply(x, 3) Out[8]: GF([24, 21, 19, 0, 29, 18, 15, 2, 20, 24], order=31) In [9]: x * 3 Out[9]: GF([24, 21, 19, 0, 29, 18, 15, 2, 20, 24], order=31)
In [10]: print(GF.properties) GF(31): characteristic: 31 degree: 1 order: 31 irreducible_poly: Poly(x + 28, GF(31)) is_primitive_poly: True primitive_element: GF(3, order=31) # Adding `characteristic` copies of any element always results in zero In [11]: x * GF.characteristic Out[11]: GF([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], order=31)
- np.negative(x)[source]¶
Returns the element-wise additive inverse of a Galois field array.
References
Examples
In [1]: GF = galois.GF(31) In [2]: x = GF.Random(10); x Out[2]: GF([18, 15, 29, 25, 1, 3, 23, 9, 5, 28], order=31) In [3]: y = np.negative(x); y Out[3]: GF([13, 16, 2, 6, 30, 28, 8, 22, 26, 3], order=31) In [4]: x + y Out[4]: GF([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], order=31)
In [5]: -x Out[5]: GF([13, 16, 2, 6, 30, 28, 8, 22, 26, 3], order=31) In [6]: -1*x Out[6]: GF([13, 16, 2, 6, 30, 28, 8, 22, 26, 3], order=31)
- np.power(x, y)[source]¶
Exponentiates a Galois field array element-wise.
References
Examples
In [1]: GF = galois.GF(31) In [2]: x = GF.Random(10); x Out[2]: GF([25, 22, 29, 1, 1, 29, 6, 14, 4, 8], order=31) In [3]: np.power(x, 3) Out[3]: GF([ 1, 15, 23, 1, 1, 23, 30, 16, 2, 16], order=31) In [4]: x ** 3 Out[4]: GF([ 1, 15, 23, 1, 1, 23, 30, 16, 2, 16], order=31) In [5]: x * x * x Out[5]: GF([ 1, 15, 23, 1, 1, 23, 30, 16, 2, 16], order=31)
In [6]: x = GF.Random(10, low=1); x Out[6]: GF([27, 21, 14, 6, 7, 9, 12, 14, 3, 6], order=31) In [7]: y = np.random.randint(-10, 10, 10); y Out[7]: array([-8, -4, 1, -6, 8, -3, -8, 1, 8, -4]) In [8]: np.power(x, y) Out[8]: GF([16, 19, 14, 1, 10, 2, 7, 14, 20, 5], order=31) In [9]: x ** y Out[9]: GF([16, 19, 14, 1, 10, 2, 7, 14, 20, 5], order=31)
- np.reciprocal(x)[source]¶
Returns the element-wise multiplicative inverse of a Galois field array.
References
Examples
In [1]: GF = galois.GF(31) In [2]: x = GF.Random(5, low=1); x Out[2]: GF([21, 8, 3, 14, 18], order=31) In [3]: y = np.reciprocal(x); y Out[3]: GF([ 3, 4, 21, 20, 19], order=31) In [4]: x * y Out[4]: GF([1, 1, 1, 1, 1], order=31)
In [5]: x ** -1 Out[5]: GF([ 3, 4, 21, 20, 19], order=31) In [6]: GF(1) / x Out[6]: GF([ 3, 4, 21, 20, 19], order=31) In [7]: GF(1) // x Out[7]: GF([ 3, 4, 21, 20, 19], order=31)
- np.square(x)[source]¶
Squares a Galois field array element-wise.
References
Examples
In [1]: GF = galois.GF(31) In [2]: x = GF.Random(10); x Out[2]: GF([24, 10, 21, 13, 10, 16, 1, 3, 6, 18], order=31) In [3]: np.square(x) Out[3]: GF([18, 7, 7, 14, 7, 8, 1, 9, 5, 14], order=31) In [4]: x ** 2 Out[4]: GF([18, 7, 7, 14, 7, 8, 1, 9, 5, 14], order=31) In [5]: x * x Out[5]: GF([18, 7, 7, 14, 7, 8, 1, 9, 5, 14], order=31)
- np.subtract(x, y)[source]¶
Subtracts two Galois field arrays element-wise.
References
Examples
In [1]: GF = galois.GF(31) In [2]: x = GF.Random(10); x Out[2]: GF([20, 10, 25, 27, 13, 29, 14, 2, 7, 2], order=31) In [3]: y = GF.Random(10); y Out[3]: GF([ 5, 4, 29, 0, 13, 20, 10, 24, 11, 0], order=31) In [4]: np.subtract(x, y) Out[4]: GF([15, 6, 27, 27, 0, 9, 4, 9, 27, 2], order=31) In [5]: x - y Out[5]: GF([15, 6, 27, 27, 0, 9, 4, 9, 27, 2], order=31)