本文整理汇总了Python中numpy.linalg.matrix_power方法的典型用法代码示例。如果您正苦于以下问题:Python linalg.matrix_power方法的具体用法?Python linalg.matrix_power怎么用?Python linalg.matrix_power使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy.linalg
的用法示例。
在下文中一共展示了linalg.matrix_power方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __pow__
# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import matrix_power [as 别名]
def __pow__(self, other):
return matrix_power(self, other)
示例2: test_returntype
# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import matrix_power [as 别名]
def test_returntype(self):
a = np.array([[0, 1], [0, 0]])
assert_(type(matrix_power(a, 2)) is np.ndarray)
a = mat(a)
assert_(type(matrix_power(a, 2)) is matrix)
示例3: test_list
# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import matrix_power [as 别名]
def test_list(self):
assert_array_equal(matrix_power([[0, 1], [0, 0]], 2), [[0, 0], [0, 0]])
示例4: test_large_power
# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import matrix_power [as 别名]
def test_large_power(self, dt):
rshft = self.rshft_1.astype(dt)
assert_equal(
matrix_power(rshft, 2**100 + 2**10 + 2**5 + 0), self.rshft_0)
assert_equal(
matrix_power(rshft, 2**100 + 2**10 + 2**5 + 1), self.rshft_1)
assert_equal(
matrix_power(rshft, 2**100 + 2**10 + 2**5 + 2), self.rshft_2)
assert_equal(
matrix_power(rshft, 2**100 + 2**10 + 2**5 + 3), self.rshft_3)
示例5: test_power_is_zero
# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import matrix_power [as 别名]
def test_power_is_zero(self, dt):
def tz(M):
mz = matrix_power(M, 0)
assert_equal(mz, identity_like_generalized(M))
assert_equal(mz.dtype, M.dtype)
for mat in self.rshft_all:
tz(mat.astype(dt))
if dt != object:
tz(self.stacked.astype(dt))
示例6: test_power_is_two
# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import matrix_power [as 别名]
def test_power_is_two(self, dt):
def tz(mat):
mz = matrix_power(mat, 2)
mmul = matmul if mat.dtype != object else dot
assert_equal(mz, mmul(mat, mat))
assert_equal(mz.dtype, mat.dtype)
for mat in self.rshft_all:
tz(mat.astype(dt))
if dt != object:
tz(self.stacked.astype(dt))
示例7: test_power_is_minus_one
# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import matrix_power [as 别名]
def test_power_is_minus_one(self, dt):
def tz(mat):
invmat = matrix_power(mat, -1)
mmul = matmul if mat.dtype != object else dot
assert_almost_equal(
mmul(invmat, mat), identity_like_generalized(mat))
for mat in self.rshft_all:
if dt not in self.dtnoinv:
tz(mat.astype(dt))
示例8: test_exceptions_bad_power
# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import matrix_power [as 别名]
def test_exceptions_bad_power(self, dt):
mat = self.rshft_0.astype(dt)
assert_raises(TypeError, matrix_power, mat, 1.5)
assert_raises(TypeError, matrix_power, mat, [1])
示例9: test_exceptions_non_square
# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import matrix_power [as 别名]
def test_exceptions_non_square(self, dt):
assert_raises(LinAlgError, matrix_power, np.array([1], dt), 1)
assert_raises(LinAlgError, matrix_power, np.array([[1], [2]], dt), 1)
assert_raises(LinAlgError, matrix_power, np.ones((4, 3, 2), dt), 1)
示例10: test_exceptions_not_invertible
# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import matrix_power [as 别名]
def test_exceptions_not_invertible(self, dt):
if dt in self.dtnoinv:
return
mat = self.noninv.astype(dt)
assert_raises(LinAlgError, matrix_power, mat, -1)
示例11: test_large_power
# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import matrix_power [as 别名]
def test_large_power(self):
assert_equal(
matrix_power(self.R90, 2 ** 100 + 2 ** 10 + 2 ** 5 + 1), self.R90)
示例12: test_large_power_trailing_zero
# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import matrix_power [as 别名]
def test_large_power_trailing_zero(self):
assert_equal(
matrix_power(self.R90, 2 ** 100 + 2 ** 10 + 2 ** 5), identity(2))
示例13: testip_zero
# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import matrix_power [as 别名]
def testip_zero(self):
def tz(M):
mz = matrix_power(M, 0)
assert_equal(mz, identity(M.shape[0]))
assert_equal(mz.dtype, M.dtype)
for M in [self.Arb22, self.arbfloat, self.large]:
yield tz, M
示例14: testip_one
# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import matrix_power [as 别名]
def testip_one(self):
def tz(M):
mz = matrix_power(M, 1)
assert_equal(mz, M)
assert_equal(mz.dtype, M.dtype)
for M in [self.Arb22, self.arbfloat, self.large]:
yield tz, M
示例15: testip_invert
# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import matrix_power [as 别名]
def testip_invert(self):
def tz(M):
mz = matrix_power(M, -1)
assert_almost_equal(identity(M.shape[0]), dot(mz, M))
for M in [self.R90, self.Arb22, self.arbfloat, self.large]:
yield tz, M