galois.GroupArray

class galois.GroupArray(array, dtype=None, copy=True, order='K', ndmin=0)

Creates an array over \((\mathbb{Z}/n\mathbb{Z}){^+}\) or \((\mathbb{Z}/n\mathbb{Z}){^\times}\).

The galois.GroupArray class is a parent class for all finite group array classes. Any finite group \((\mathbb{Z}/n\mathbb{Z}){^+}\) or \((\mathbb{Z}/n\mathbb{Z}){^\times}\) can be constructed by calling the class factory galois.Group(n, "+") or galois.Group(n, "*").

Warning

This is an abstract base class for all finite group array classes. galois.GroupArray cannot be instantiated directly. Instead, finite group array classes are created using galois.Group().

For example, one can create the \((\mathbb{Z}/16\mathbb{Z}){^+}\) finite additive group array class as follows:

In [279]: G = galois.Group(16, "+")

In [280]: print(G.properties)
(ℤ/16ℤ)+:
  structure: Finite Additive Group
  modulus: 16
  order: 16
  generator: 1
  is_cyclic: True
  is_abelian: True

This subclass can then be used to instantiate arrays over \((\mathbb{Z}/16\mathbb{Z}){^+}\).

In [281]: G([3,5,0,2,1])
Out[281]: ℤn+([3, 5, 0, 2, 1], n=16)

In [282]: G.Random((2,5))
Out[282]: 
ℤn+([[11,  0,  3, 11,  3],
     [ 4,  4, 14,  4,  2]], n=16)

Creating the \((\mathbb{Z}/16\mathbb{Z}){^\times}\) finite multiplicative group array class is just as easy:

In [283]: G = galois.Group(16, "*")

In [284]: print(G.properties)
(ℤ/16ℤ)*:
  structure: Finite Multiplicative Group
  modulus: 16
  order: 8
  generator: None
  is_cyclic: False
  is_abelian: True

In [285]: G.Random((2,5))
Out[285]: 
ℤn*([[ 9, 15,  5, 15,  3],
     [ 9,  9, 15, 11,  1]], n=16)

galois.GroupArray is a subclass of numpy.ndarray. The galois.GroupArray constructor has the same syntax as numpy.array(). The returned galois.GroupArray object is an array that can be acted upon like any other numpy array.

Parameters
  • array (array_like) – The input array to be converted to a finite group array. The input array is copied, so the original array is unmodified by changes to the finite group array. Valid input array types are numpy.ndarray, list or tuple of int, or int.

  • dtype (numpy.dtype, optional) – The numpy.dtype of the array elements. The default is None which represents the smallest valid dtype for this class, i.e. the first element in galois.GroupMeta.dtypes.

  • copy (bool, optional) – The copy keyword argument from numpy.array(). The default is True which makes a copy of the input object is it’s an array.

  • order ({"K", "A", "C", "F"}, optional) – The order keyword argument from numpy.array(). Valid values are "K" (default), "A", "C", or "F".

  • ndmin (int, optional) – The ndmin keyword argument from numpy.array(). The minimum number of dimensions of the output. The default is 0.

Returns

The copied input array as a finite group array.

Return type

galois.GroupArray

Constructors

Elements([dtype])

Creates a finite group array of the group’s elements.

Ones(shape[, dtype])

Creates a finite group array with all ones.

Random([shape, low, high, dtype])

Creates a finite group array with random group elements.

Range(start, stop[, step, dtype])

Creates a finite group array with a range of group elements.

Zeros(shape[, dtype])

Creates a finite group array with all zeros.

Methods

classmethod Elements(dtype=None)[source]

Creates a finite group array of the group’s elements.

Parameters

dtype (numpy.dtype, optional) – The numpy.dtype of the array elements. The default is None which represents the smallest valid dtype for this class, i.e. the first element in galois.GroupMeta.dtypes.

Returns

A finite group array of all the group’s elements.

Return type

galois.GroupArray

Examples

In [286]: G = galois.Group(16, "+")

In [287]: G.Elements()
Out[287]: 
ℤn+([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15],
    n=16)
In [288]: G = galois.Group(16, "*")

In [289]: G.Elements()
Out[289]: ℤn*([ 1,  3,  5,  7,  9, 11, 13, 15], n=16)
classmethod Ones(shape, dtype=None)[source]

Creates a finite group array with all ones.

Parameters
  • shape (tuple) – A numpy-compliant shape tuple, see numpy.ndarray.shape. An empty tuple () represents a scalar. A single integer or 1-tuple, e.g. N or (N,), represents the size of a 1-dim array. An n-tuple, e.g. (M,N), represents an n-dim array with each element indicating the size in each dimension.

  • dtype (numpy.dtype, optional) – The numpy.dtype of the array elements. The default is None which represents the smallest valid dtype for this class, i.e. the first element in galois.GroupMeta.dtypes.

Returns

A finite group array of ones.

Return type

galois.GroupArray

Examples

In [290]: G = galois.Group(16, "*")

In [291]: G.Ones((2,5))
Out[291]: 
ℤn*([[1, 1, 1, 1, 1],
     [1, 1, 1, 1, 1]], n=16)
classmethod Random(shape=(), low=0, high=None, dtype=None)[source]

Creates a finite group array with random group elements.

Parameters
  • shape (tuple) – A numpy-compliant shape tuple, see numpy.ndarray.shape. An empty tuple () represents a scalar. A single integer or 1-tuple, e.g. N or (N,), represents the size of a 1-dim array. An n-tuple, e.g. (M,N), represents an n-dim array with each element indicating the size in each dimension.

  • low (int, optional) – The lowest value (inclusive) of a random group element. The default is 0.

  • high (int, optional) – The highest value (exclusive) of a random group element. The default is None which represents the group’s modulus \(n\).

  • dtype (numpy.dtype, optional) – The numpy.dtype of the array elements. The default is None which represents the smallest valid dtype for this class, i.e. the first element in galois.GroupMeta.dtypes.

Returns

A finite group array of random group elements.

Return type

galois.GroupArray

Examples

In [292]: G = galois.Group(16, "*")

In [293]: G.Random((2,5))
Out[293]: 
ℤn*([[11, 11,  9,  7,  1],
     [ 1,  3,  1, 11,  3]], n=16)
classmethod Range(start, stop, step=1, dtype=None)[source]

Creates a finite group array with a range of group elements.

This constructor is only valid for additive groups since multiplicative groups don’t have equally-spaced elements.

Parameters
  • start (int) – The starting value (inclusive).

  • stop (int) – The stopping value (exclusive).

  • step (int, optional) – The space between values. The default is 1.

  • dtype (numpy.dtype, optional) – The numpy.dtype of the array elements. The default is None which represents the smallest valid dtype for this class, i.e. the first element in galois.GroupMeta.dtypes.

Returns

A finite group array of a range of group elements.

Return type

galois.GroupArray

Examples

In [294]: G = galois.Group(36, "+")

In [295]: G.Range(10, 20)
Out[295]: ℤn+([10, 11, 12, 13, 14, 15, 16, 17, 18, 19], n=36)
classmethod Zeros(shape, dtype=None)[source]

Creates a finite group array with all zeros.

This constructor is only valid for additive groups, since 0 is not an element of multiplicative groups.

Parameters
  • shape (tuple) – A numpy-compliant shape tuple, see numpy.ndarray.shape. An empty tuple () represents a scalar. A single integer or 1-tuple, e.g. N or (N,), represents the size of a 1-dim array. An n-tuple, e.g. (M,N), represents an n-dim array with each element indicating the size in each dimension.

  • dtype (numpy.dtype, optional) – The numpy.dtype of the array elements. The default is None which represents the smallest valid dtype for this class, i.e. the first element in galois.GroupMeta.dtypes.

Returns

A finite group array of zeros.

Return type

galois.GroupArray

Examples

In [296]: G = galois.Group(16, "+")

In [297]: G.Zeros((2,5))
Out[297]: 
ℤn+([[0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0]], n=16)