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([10, 13, 14, 18, 20, 2, 16, 2, 16, 29], order=31) In [3]: y = GF.Random(10); y Out[3]: GF([28, 2, 23, 30, 21, 14, 27, 11, 27, 17], order=31) In [4]: np.add(x, y) Out[4]: GF([ 7, 15, 6, 17, 10, 16, 12, 13, 12, 15], order=31) In [5]: x + y Out[5]: GF([ 7, 15, 6, 17, 10, 16, 12, 13, 12, 15], 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([[0, 3], [2, 0]], order=2^3) In [3]: B = GF.Random((2,2)); B Out[3]: GF([[3, 4], [5, 7]], order=2^3) In [4]: np.concatenate((A,B), axis=0) Out[4]: GF([[0, 3], [2, 0], [3, 4], [5, 7]], order=2^3) In [5]: np.concatenate((A,B), axis=1) Out[5]: GF([[0, 3, 3, 4], [2, 0, 5, 7]], 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([21, 18, 9, 18, 4, 29, 7, 22, 23, 25], order=31) In [3]: y = GF.Random(10, low=1); y Out[3]: GF([22, 19, 29, 2, 26, 21, 2, 24, 13, 25], order=31) In [4]: z = np.divide(x, y); z Out[4]: GF([ 8, 14, 11, 9, 24, 25, 19, 19, 28, 1], order=31) In [5]: y * z Out[5]: GF([21, 18, 9, 18, 4, 29, 7, 22, 23, 25], order=31)
In [6]: np.true_divide(x, y) Out[6]: GF([ 8, 14, 11, 9, 24, 25, 19, 19, 28, 1], order=31) In [7]: x / y Out[7]: GF([ 8, 14, 11, 9, 24, 25, 19, 19, 28, 1], order=31) In [8]: np.floor_divide(x, y) Out[8]: GF([ 8, 14, 11, 9, 24, 25, 19, 19, 28, 1], order=31) In [9]: x // y Out[9]: GF([ 8, 14, 11, 9, 24, 25, 19, 19, 28, 1], 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([2, 6, 1, 3, 0], order=2^3) In [3]: np.insert(x, 1, [0,1,2,3]) Out[3]: GF([2, 0, 1, 2, 3, 6, 1, 3, 0], 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, 13, 24, 15, 9, 20, 1, 28, 25, 16], order=31) In [4]: y = np.log(x); y Out[4]: GF([22, 11, 13, 21, 2, 8, 0, 16, 10, 6], order=31) In [5]: alpha ** y Out[5]: GF([14, 13, 24, 15, 9, 20, 1, 28, 25, 16], 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([[ 5, 14, 4, 25], [25, 18, 4, 5], [ 0, 18, 1, 15]], order=31) In [3]: x2 = GF.Random((4,5)); x2 Out[3]: GF([[27, 7, 4, 5, 18], [ 4, 28, 27, 19, 25], [19, 24, 7, 25, 13], [30, 13, 25, 8, 11]], order=31) In [4]: np.matmul(x1, x2) Out[4]: GF([[25, 11, 28, 2, 23], [12, 3, 26, 18, 15], [14, 10, 0, 22, 8]], order=31) In [5]: x1 @ x2 Out[5]: GF([[25, 11, 28, 2, 23], [12, 3, 26, 18, 15], [14, 10, 0, 22, 8]], 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([28, 20, 18, 6, 22, 26, 26, 25, 22, 23], order=31) In [3]: y = GF.Random(10); y Out[3]: GF([13, 14, 26, 16, 13, 27, 1, 13, 21, 28], order=31) In [4]: np.multiply(x, y) Out[4]: GF([23, 1, 3, 3, 7, 20, 26, 15, 28, 24], order=31) In [5]: x * y Out[5]: GF([23, 1, 3, 3, 7, 20, 26, 15, 28, 24], 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([21, 28, 23, 13, 11, 0, 3, 7, 0, 17], order=31) In [8]: np.multiply(x, 3) Out[8]: GF([ 1, 22, 7, 8, 2, 0, 9, 21, 0, 20], order=31) In [9]: x * 3 Out[9]: GF([ 1, 22, 7, 8, 2, 0, 9, 21, 0, 20], 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([20, 30, 30, 19, 4, 1, 14, 8, 17, 8], order=31) In [3]: y = np.negative(x); y Out[3]: GF([11, 1, 1, 12, 27, 30, 17, 23, 14, 23], 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([11, 1, 1, 12, 27, 30, 17, 23, 14, 23], order=31) In [6]: -1*x Out[6]: GF([11, 1, 1, 12, 27, 30, 17, 23, 14, 23], 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([19, 2, 26, 28, 29, 8, 5, 25, 26, 3], order=31) In [3]: np.power(x, 3) Out[3]: GF([ 8, 8, 30, 4, 23, 16, 1, 1, 30, 27], order=31) In [4]: x ** 3 Out[4]: GF([ 8, 8, 30, 4, 23, 16, 1, 1, 30, 27], order=31) In [5]: x * x * x Out[5]: GF([ 8, 8, 30, 4, 23, 16, 1, 1, 30, 27], order=31)
In [6]: x = GF.Random(10, low=1); x Out[6]: GF([ 1, 13, 11, 7, 5, 23, 18, 5, 27, 22], order=31) In [7]: y = np.random.randint(-10, 10, 10); y Out[7]: array([ 9, -8, -2, 4, -7, 2, -8, 5, 4, -3]) In [8]: np.power(x, y) Out[8]: GF([ 1, 9, 10, 14, 25, 2, 9, 25, 8, 29], order=31) In [9]: x ** y Out[9]: GF([ 1, 9, 10, 14, 25, 2, 9, 25, 8, 29], 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([29, 18, 28, 27, 19], order=31) In [3]: y = np.reciprocal(x); y Out[3]: GF([15, 19, 10, 23, 18], order=31) In [4]: x * y Out[4]: GF([1, 1, 1, 1, 1], order=31)
In [5]: x ** -1 Out[5]: GF([15, 19, 10, 23, 18], order=31) In [6]: GF(1) / x Out[6]: GF([15, 19, 10, 23, 18], order=31) In [7]: GF(1) // x Out[7]: GF([15, 19, 10, 23, 18], 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([ 2, 20, 29, 7, 9, 12, 17, 3, 23, 27], order=31) In [3]: np.square(x) Out[3]: GF([ 4, 28, 4, 18, 19, 20, 10, 9, 2, 16], order=31) In [4]: x ** 2 Out[4]: GF([ 4, 28, 4, 18, 19, 20, 10, 9, 2, 16], order=31) In [5]: x * x Out[5]: GF([ 4, 28, 4, 18, 19, 20, 10, 9, 2, 16], 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([ 6, 28, 30, 3, 23, 9, 5, 12, 7, 1], order=31) In [3]: y = GF.Random(10); y Out[3]: GF([28, 22, 8, 22, 17, 26, 24, 27, 11, 29], order=31) In [4]: np.subtract(x, y) Out[4]: GF([ 9, 6, 22, 12, 6, 14, 12, 16, 27, 3], order=31) In [5]: x - y Out[5]: GF([ 9, 6, 22, 12, 6, 14, 12, 16, 27, 3], order=31)