TESTS:
sage: R.<a,b> = QQ[]
sage: m = matrix(R,2,[0,a,b,b^2])
sage: loads(dumps(m)) == m
True
Differentiate with respect to var by differentiating each element with respect to var.
See also
derivative()
EXAMPLES:
sage: m = matrix(2, [x^i for i in range(4)])
sage: m._derivative(x)
[ 0 1]
[ 2*x 3*x^2]
Returns the elementwise product of two dense matrices with identical base rings.
This routine assumes that self and right are both matrices, both dense, with identical sizes and with identical base rings. It is “unsafe” in the sense that these conditions are not checked and no sensible errors are raised.
This routine is meant to be called from the
meth:
method, which will ensure that this routine receives
proper input. More thorough documentation is provided
there.
EXAMPLE:
sage: A = matrix(ZZ, 2, range(6), sparse=False)
sage: B = matrix(ZZ, 2, [1,0,2,0,3,0], sparse=False)
sage: A._elementwise_product(B)
[ 0 0 4]
[ 0 12 0]
AUTHOR:
Multiply the matrices left and right using the classical
algorithm.
This method assumes that left and right have the same parent and compatible dimensions.
Returns the antitranspose of self, without changing self.
EXAMPLES:
sage: A = matrix(2,3,range(6)); A
[0 1 2]
[3 4 5]
sage: A.antitranspose()
[5 2]
[4 1]
[3 0]
sage: A.subdivide(1,2); A
[0 1|2]
[---+-]
[3 4|5]
sage: A.antitranspose()
[5|2]
[-+-]
[4|1]
[3|0]
Apply the given map phi (an arbitrary Python function or callable object) to this dense matrix. If R is not given, automatically determine the base ring of the resulting matrix.
OUTPUT: a matrix over R
EXAMPLES:
sage: m = matrix(ZZ, 3, range(9))
sage: k.<a> = GF(9)
sage: f = lambda x: k(x)
sage: n = m.apply_map(f); n
[0 1 2]
[0 1 2]
[0 1 2]
sage: n.parent()
Full MatrixSpace of 3 by 3 dense matrices over Finite Field in a of size 3^2
In this example, we explicitly specify the codomain.
sage: s = GF(3)
sage: f = lambda x: s(x)
sage: n = m.apply_map(f, k); n
[0 1 2]
[0 1 2]
[0 1 2]
sage: n.parent()
Full MatrixSpace of 3 by 3 dense matrices over Finite Field in a of size 3^2
If self is subdivided, the result will be as well:
sage: m = matrix(2, 2, srange(4))
sage: m.subdivide(None, 1); m
[0|1]
[2|3]
sage: m.apply_map(lambda x: x*x)
[0|1]
[4|9]
If the map sends most of the matrix to zero, then it may be useful to get the result as a sparse matrix.
sage: m = matrix(ZZ, 3, 3, range(1, 10))
sage: n = m.apply_map(lambda x: 1//x, sparse=True); n
[1 0 0]
[0 0 0]
[0 0 0]
sage: n.parent()
Full MatrixSpace of 3 by 3 sparse matrices over Integer Ring
TESTS:
sage: m = matrix([])
sage: m.apply_map(lambda x: x*x) == m
True
sage: m.apply_map(lambda x: x*x, sparse=True).parent()
Full MatrixSpace of 0 by 0 sparse matrices over Integer Ring
Apply the morphism phi to the coefficients of this dense matrix.
The resulting matrix is over the codomain of phi.
INPUT:
OUTPUT: a matrix over the codomain of phi
EXAMPLES:
sage: m = matrix(ZZ, 3, range(9))
sage: phi = ZZ.hom(GF(5))
sage: m.apply_morphism(phi)
[0 1 2]
[3 4 0]
[1 2 3]
sage: parent(m.apply_morphism(phi))
Full MatrixSpace of 3 by 3 dense matrices over Finite Field of size 5
We apply a morphism to a matrix over a polynomial ring:
sage: R.<x,y> = QQ[]
sage: m = matrix(2, [x,x^2 + y, 2/3*y^2-x, x]); m
[ x x^2 + y]
[2/3*y^2 - x x]
sage: phi = R.hom([y,x])
sage: m.apply_morphism(phi)
[ y y^2 + x]
[2/3*x^2 - y y]
Returns the transpose of self, without changing self.
EXAMPLES: We create a matrix, compute its transpose, and note that the original matrix is not changed.
sage: M = MatrixSpace(QQ, 2)
sage: A = M([1,2,3,4])
sage: B = A.transpose()
sage: print B
[1 3]
[2 4]
sage: print A
[1 2]
[3 4]
sage: A.subdivide(None, 1); A
[1|2]
[3|4]
sage: A.transpose()
[1 3]
[---]
[2 4]