本文整理汇总了Python中sage.matrix.matrix_space.MatrixSpace.identity_matrix方法的典型用法代码示例。如果您正苦于以下问题:Python MatrixSpace.identity_matrix方法的具体用法?Python MatrixSpace.identity_matrix怎么用?Python MatrixSpace.identity_matrix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.matrix.matrix_space.MatrixSpace
的用法示例。
在下文中一共展示了MatrixSpace.identity_matrix方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: matId
# 需要导入模块: from sage.matrix.matrix_space import MatrixSpace [as 别名]
# 或者: from sage.matrix.matrix_space.MatrixSpace import identity_matrix [as 别名]
def matId(n):
Id = []
n2 = n.quo_rem(2)[0]
for j in range(n2):
MSn = MatrixSpace(F, n2-j, n2-j)
Id.append(MSn.identity_matrix())
return Id
示例2: matA
# 需要导入模块: from sage.matrix.matrix_space import MatrixSpace [as 别名]
# 或者: from sage.matrix.matrix_space.MatrixSpace import identity_matrix [as 别名]
def matA(n):
A = []
n2 = n.quo_rem(2)[0]
for j in range(n2+2):
MS0 = MatrixSpace(F, j, j)
I = MS0.identity_matrix()
O = MS0(j*j*[1])
A.append(I+O)
return A
示例3: RandomLinearCode
# 需要导入模块: from sage.matrix.matrix_space import MatrixSpace [as 别名]
# 或者: from sage.matrix.matrix_space.MatrixSpace import identity_matrix [as 别名]
def RandomLinearCode(n,k,F):
r"""
The method used is to first construct a `k \times n`
matrix using Sage's random_element method for the MatrixSpace
class. The construction is probabilistic but should only fail
extremely rarely.
INPUT: Integers n,k, with `n>k`, and a finite field F
OUTPUT: Returns a "random" linear code with length n, dimension k
over field F.
EXAMPLES::
sage: C = codes.RandomLinearCode(30,15,GF(2))
sage: C
Linear code of length 30, dimension 15 over Finite Field of size 2
sage: C = codes.RandomLinearCode(10,5,GF(4,'a'))
sage: C
Linear code of length 10, dimension 5 over Finite Field in a of size 2^2
AUTHORS:
- David Joyner (2007-05)
"""
MS = MatrixSpace(F,k,n)
for i in range(50):
G = MS.random_element()
if G.rank() == k:
V = span(G.rows(), F)
return LinearCodeFromVectorSpace(V) # may not be in standard form
MS1 = MatrixSpace(F,k,k)
MS2 = MatrixSpace(F,k,n-k)
Ik = MS1.identity_matrix()
A = MS2.random_element()
G = Ik.augment(A)
return LinearCode(G) # in standard form
示例4: __call__
# 需要导入模块: from sage.matrix.matrix_space import MatrixSpace [as 别名]
# 或者: from sage.matrix.matrix_space.MatrixSpace import identity_matrix [as 别名]
def __call__(self, A, name=''):
r"""
Create an element of the homspace ``self`` from `A`.
INPUT:
- ``A`` -- one of the following:
- an element of a Hecke algebra
- a Hecke module morphism
- a matrix
- a list of elements of the codomain specifying the images
of the basis elements of the domain.
EXAMPLES::
sage: M = ModularForms(Gamma0(7), 4)
sage: H = M.Hom(M)
sage: H(M.hecke_operator(7))
Hecke module morphism T_7 defined by the matrix
[ -7 0 0]
[ 0 1 240]
[ 0 0 343]
Domain: Modular Forms space of dimension 3 for Congruence Subgroup Gamma0(7) ...
Codomain: Modular Forms space of dimension 3 for Congruence Subgroup Gamma0(7) ...
sage: H(H(M.hecke_operator(7)))
Hecke module morphism T_7 defined by the matrix
[ -7 0 0]
[ 0 1 240]
[ 0 0 343]
Domain: Modular Forms space of dimension 3 for Congruence Subgroup Gamma0(7) ...
Codomain: Modular Forms space of dimension 3 for Congruence Subgroup Gamma0(7) ...
sage: H(matrix(QQ, 3, srange(9)))
Hecke module morphism defined by the matrix
[0 1 2]
[3 4 5]
[6 7 8]
Domain: Modular Forms space of dimension 3 for Congruence Subgroup Gamma0(7) ...
Codomain: Modular Forms space of dimension 3 for Congruence Subgroup Gamma0(7) ...
TESTS:
Make sure that the element is created correctly when the codomain is
not the full module (related to :trac:`21497`)::
sage: M = ModularSymbols(Gamma0(3),weight=22,sign=1)
sage: S = M.cuspidal_subspace()
sage: H = S.Hom(S)
sage: H(S.gens())
Hecke module morphism defined by the matrix
[1 0 0 0 0 0]
[0 1 0 0 0 0]
[0 0 1 0 0 0]
[0 0 0 1 0 0]
[0 0 0 0 1 0]
[0 0 0 0 0 1]
Domain: Modular Symbols subspace of dimension 6 of Modular Symbols space ...
Codomain: Modular Symbols subspace of dimension 6 of Modular Symbols space ...
sage: H.zero() in H
True
sage: H.one() in H
True
"""
try:
if A.parent() == self:
A._set_parent(self)
return A
A = A.hecke_module_morphism()
if A.parent() == self:
A._set_parent(self)
return A
else:
raise TypeError("unable to coerce A to self")
except AttributeError:
pass
if A in self.base_ring():
dim_dom = self.domain().rank()
dim_codom = self.codomain().rank()
MS = MatrixSpace(self.base_ring(), dim_dom, dim_codom)
if self.domain() == self.codomain():
A = A * MS.identity_matrix()
elif A == 0:
A = MS.zero()
else:
raise ValueError('scalars do not coerce to this homspace')
elif isinstance(A, (list, tuple)):
A = matrix([self.codomain().coordinate_vector(f) for f in A])
return HeckeModuleMorphism_matrix(self, A, name)
示例5: AlternatingSignMatrices
# 需要导入模块: from sage.matrix.matrix_space import MatrixSpace [as 别名]
# 或者: from sage.matrix.matrix_space.MatrixSpace import identity_matrix [as 别名]
#.........这里部分代码省略.........
def _element_constructor_(self, asm):
"""
Construct an element of ``self``.
EXAMPLES::
sage: A = AlternatingSignMatrices(3)
sage: elt = A([[1, 0, 0],[0, 1, 0],[0, 0, 1]]); elt
[1 0 0]
[0 1 0]
[0 0 1]
sage: elt.parent() is A
True
sage: A([[3, 2, 1], [2, 1], [1]])
[1 0 0]
[0 1 0]
[0 0 1]
"""
if isinstance(asm, AlternatingSignMatrix):
if asm.parent() is self:
return asm
raise ValueError("Cannot convert between alternating sign matrices of different sizes")
if asm in MonotoneTriangles(self._n):
return self.from_monotone_triangle(asm)
return self.element_class(self, self._matrix_space(asm))
Element = AlternatingSignMatrix
def _an_element_(self):
"""
Return an element of ``self``.
"""
return self.element_class(self, self._matrix_space.identity_matrix())
def from_monotone_triangle(self, triangle):
r"""
Return an alternating sign matrix from a monotone triangle.
EXAMPLES::
sage: A = AlternatingSignMatrices(3)
sage: A.from_monotone_triangle([[3, 2, 1], [2, 1], [1]])
[1 0 0]
[0 1 0]
[0 0 1]
sage: A.from_monotone_triangle([[3, 2, 1], [3, 2], [3]])
[0 0 1]
[0 1 0]
[1 0 0]
"""
n = len(triangle)
if n != self._n:
raise ValueError("Incorrect size")
asm = []
prev = [0]*n
for line in reversed(triangle):
v = [1 if j+1 in reversed(line) else 0 for j in range(n)]
row = [a-b for (a, b) in zip(v, prev)]
asm.append(row)
prev = v
return self.element_class(self, self._matrix_space(asm))
def size(self):