我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用numpy.linalg.matrix_power()。
def __verify_spectral(self, C, p_failure): d = C.shape[0] c = 1 # some constant if not hasattr(self, 'i_verify'): self.i_verify = 0 self.i_verify += 1 p_failure_i = p_failure / (2 * (self.i_verify ** 2)) # pick a point uniformly at ranom from the d-dimensional unit sphere # http://stackoverflow.com/questions/15880367/python-uniform-distribution-of-points-on-4-dimensional-sphere normal_deviates = np.random.normal(size=(d, 1)) radius = np.sqrt((normal_deviates ** 2).sum(axis=0)) x = normal_deviates / radius return ln.norm(np.dot(ln.matrix_power(C, int(c * np.log(d / p_failure_i))), x)) <= 1
def test_large_power(self): assert_equal( matrix_power(self.R90, 2 ** 100 + 2 ** 10 + 2 ** 5 + 1), self.R90)
def test_large_power_trailing_zero(self): assert_equal( matrix_power(self.R90, 2 ** 100 + 2 ** 10 + 2 ** 5), identity(2))
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
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
def testip_two(self): def tz(M): mz = matrix_power(M, 2) assert_equal(mz, dot(M, M)) assert_equal(mz.dtype, M.dtype) for M in [self.Arb22, self.arbfloat, self.large]: yield tz, M
def test_invert_noninvertible(self): import numpy.linalg assert_raises(numpy.linalg.linalg.LinAlgError, lambda: matrix_power(self.noninv, -1))
def test_square(self): A = array([[True, False], [True, True]]) assert_equal(matrix_power(A, 2), A)
def generate_Q(n,q_power): ''' Generate Q^{q_power} for n variables. ''' transition_matrix = generate_grid_transition_matrix(n) q_tmp = tr_0 = np.identity(n**2) for k in range(1,q_power+1): q_tmp += LA.matrix_power(transition_matrix, k) return np.array(normalize(q_tmp, norm='l1', axis=1),dtype = 'float32')