Vectors with elements in \(\GF{2}\)#
AUTHOR:
Martin Albrecht (2009-12): initial implementation
Thomas Feulner (2012-11): added
Vector_mod2_dense.hamming_weight()
EXAMPLES:
sage: VS = GF(2)^3
sage: e = VS.random_element()
sage: e.parent() is VS
True
sage: S = set(vector(v, immutable=True) for v in VS)
sage: S1 = set()
sage: while S != S1:
....: S1.add(vector(VS.random_element(), immutable=True))
>>> from sage.all import *
>>> VS = GF(Integer(2))**Integer(3)
>>> e = VS.random_element()
>>> e.parent() is VS
True
>>> S = set(vector(v, immutable=True) for v in VS)
>>> S1 = set()
>>> while S != S1:
... S1.add(vector(VS.random_element(), immutable=True))
- class sage.modules.vector_mod2_dense.Vector_mod2_dense[source]#
Bases:
FreeModuleElement
EXAMPLES:
sage: VS = VectorSpace(GF(2),3) sage: VS((0,0,1/3)) (0, 0, 1) sage: type(_) <class 'sage.modules.vector_mod2_dense.Vector_mod2_dense'> sage: VS((0,0,int(3))) (0, 0, 1) sage: VS((0,0,3)) (0, 0, 1) sage: VS((0,0,GF(2)(1))) (0, 0, 1)
>>> from sage.all import * >>> VS = VectorSpace(GF(Integer(2)),Integer(3)) >>> VS((Integer(0),Integer(0),Integer(1)/Integer(3))) (0, 0, 1) >>> type(_) <class 'sage.modules.vector_mod2_dense.Vector_mod2_dense'> >>> VS((Integer(0),Integer(0),int(Integer(3)))) (0, 0, 1) >>> VS((Integer(0),Integer(0),Integer(3))) (0, 0, 1) >>> VS((Integer(0),Integer(0),GF(Integer(2))(Integer(1)))) (0, 0, 1)
- hamming_weight()[source]#
Return the number of positions
i
such thatself[i] != 0
.EXAMPLES:
sage: vector(GF(2), [1,1,0]).hamming_weight() 2
>>> from sage.all import * >>> vector(GF(Integer(2)), [Integer(1),Integer(1),Integer(0)]).hamming_weight() 2
- list(copy=True)[source]#
Return a list of entries in
self
.INPUT:
copy
– alwaysTrue
EXAMPLES:
sage: VS = VectorSpace(GF(2), 10) sage: entries = [GF(2).random_element() for _ in range(10)] sage: e = VS(entries) sage: e.list() == entries True
>>> from sage.all import * >>> VS = VectorSpace(GF(Integer(2)), Integer(10)) >>> entries = [GF(Integer(2)).random_element() for _ in range(Integer(10))] >>> e = VS(entries) >>> e.list() == entries True
- sage.modules.vector_mod2_dense.unpickle_v0(parent, entries, degree, is_immutable)[source]#
EXAMPLES:
sage: from sage.modules.vector_mod2_dense import unpickle_v0 sage: VS = VectorSpace(GF(2),10) sage: unpickle_v0(VS, [0,1,2,3,4,5,6,7,8,9], 10, 0) (0, 1, 0, 1, 0, 1, 0, 1, 0, 1)
>>> from sage.all import * >>> from sage.modules.vector_mod2_dense import unpickle_v0 >>> VS = VectorSpace(GF(Integer(2)),Integer(10)) >>> unpickle_v0(VS, [Integer(0),Integer(1),Integer(2),Integer(3),Integer(4),Integer(5),Integer(6),Integer(7),Integer(8),Integer(9)], Integer(10), Integer(0)) (0, 1, 0, 1, 0, 1, 0, 1, 0, 1)