当前位置: 首页>>代码示例>>Python>>正文


Python Matrix.identity方法代码示例

本文整理汇总了Python中matrix.Matrix.identity方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.identity方法的具体用法?Python Matrix.identity怎么用?Python Matrix.identity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matrix.Matrix的用法示例。


在下文中一共展示了Matrix.identity方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testInverse

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import identity [as 别名]
 def testInverse(self):
     matrix = Matrix([1, 4, 0], [0, -3, 4], [1, 2, 2])
     self.assertEquals(
         matrix.identity(2),
         matrix.identity(2).inverse())
     self.assertEquals(
         Matrix([7, -3], [-2, 1]),
         Matrix([1, 3], [2, 7]).inverse())
     self.assertEquals(
         matrix.identity(3),
         matrix * matrix.inverse())
开发者ID:svinepels,项目名称:Python,代码行数:13,代码来源:matrix_test.py

示例2: train

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import identity [as 别名]
 def train(self, vector):
     matrix_2 = Matrix(vector)
     matrix_1 = Matrix(matrix_2.transpose())
     matrix_3 = matrix_2 * matrix_1
     identity = Matrix.identity(len(vector))
     matrix_4 = matrix_3 - identity
     self.weight = self.weight + matrix_4
开发者ID:EduardRakov,项目名称:hopfieldNetwork,代码行数:9,代码来源:hopfield_network.py

示例3: QR_decomposition

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import identity [as 别名]
 def QR_decomposition(mtrx):
     q = Matrix.identity(mtrx.size)
     a_k = mtrx.copy()
     for i in range(mtrx.size[1] - 1):
         h_k = QREigenvalueAlgorithm.get_householder_transform(a_k, i)
         q = q * h_k
         a_k = h_k * a_k
     return q, a_k  # R = a_k; QR = A (mtrx)
开发者ID:kri-k,项目名称:Numerical_methods,代码行数:10,代码来源:qr_eigenvalue_algorithm.py

示例4: testDeterminant

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import identity [as 别名]
 def testDeterminant(self):
     self.assertEquals(
         5,
         Matrix([5]).det())
     self.assertEquals(
         1,
         Matrix.identity(4).det())
     self.assertEquals(
         -141,
         Matrix([1, 4, 3, 5], [2, 4, 5, 3], [0, 5, 7, 2], [1, 1, 3, 5]).det())
开发者ID:svinepels,项目名称:Python,代码行数:12,代码来源:matrix_test.py

示例5: testPower

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import identity [as 别名]
 def testPower(self):
     matrix = Matrix([2, 0], [0, 2])
     self.assertEquals(
         matrix.power(1),
         matrix)
     self.assertEquals(
         matrix.power(3),
         Matrix([8, 0], [0, 8]))
     self.assertEquals(
         Matrix.identity(3),
         Matrix([0, 6, 7], [3, -4, 2], [0, 4, 4]).power(0))
     self.assertEquals(
         Matrix([0.25, 0.0], [0.0, 0.25]),
         Matrix([2, 0], [0, 2]).power(-2))
开发者ID:svinepels,项目名称:Python,代码行数:16,代码来源:matrix_test.py

示例6: get_householder_transform

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import identity [as 别名]
 def get_householder_transform(mtrx, col):
     sum_pow_2 = 0
     for i in range(col, mtrx.size[0]):
         sum_pow_2 += mtrx[i][col] ** 2
     v = Matrix((mtrx.size[0], 1))
     v[col][0] = mtrx[col][col] + math.copysign(math.sqrt(sum_pow_2), mtrx[col][col])
     for i in range(col + 1, mtrx.size[0]):
         v[i][0] = mtrx[i][col]
     h_mtrx = Matrix.identity(mtrx.size)
     transpose_v = v.transpose()
     tmp_mtrx = v * transpose_v
     tmp_mtrx *= 2 / (transpose_v * v)[0][0]
     h_mtrx -= tmp_mtrx
     return h_mtrx
开发者ID:kri-k,项目名称:Numerical_methods,代码行数:16,代码来源:qr_eigenvalue_algorithm.py

示例7: __get_rotation_matrix

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import identity [as 别名]
 def __get_rotation_matrix(mtrx, row, col):
     if mtrx[row][row] == mtrx[col][col]:
         angle = math.pi / 4
     else:
         angle = math.atan(2 * mtrx[row][col] / (mtrx[row][row] - mtrx[col][col]))
         angle /= 2
     s = math.sin(angle)
     c = math.cos(angle)
     u = Matrix.identity(mtrx.size)
     u[row][col] = -s
     u[col][row] = s
     u[row][row] = c
     u[col][col] = c
     return u
开发者ID:kri-k,项目名称:Numerical_methods,代码行数:16,代码来源:jacobi_eigenvalue_algorithm.py

示例8: calculate_matrix_A

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import identity [as 别名]
def calculate_matrix_A(m, L, delta1, delta2, alpha, beta):
	h = 1.0 / (m + 1)
	
	T = Matrix.toeplitz_tridiagonal(m, 1, -2, 1)
	I = Matrix.identity(m)
	
	tau1 = (1.0 / pow(h, 2)) * (delta1 / pow(L, 2))
	tau2 = (1.0 / pow(h, 2)) * (delta2 / pow(L, 2))
	
	mat11 = (T * tau1) + (I * (beta - 1))
	mat12 = (I * pow(alpha, 2))
	mat21 = (I * -beta)
	mat22 = (T * tau2) - (I * pow(alpha, 2))
	
	mat_list = [[ mat11, mat12 ], [ mat21, mat22 ]]

	return Matrix.from_mat_lists(mat_list)
开发者ID:federicotdn,项目名称:mna-tp1,代码行数:19,代码来源:problem1.py

示例9: __init__

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import identity [as 别名]
    def __init__(self, A, H, x, P, Q, R):
        """
        Initialize the Kalman Filter matrices. This implementation skips the
        control input vector. Symbols used:

        :param Matrix A: state transition matrix - predict next state from current one
        :param Matrix H: observation matrix, calculate measurement from the state
        :param Matrix x: initial estimate of the state
        :param Matrix P: initial estimate of the state covariance matrix
        :param Matrix Q: estimated process covariance
        :param Matrix R: estimated measurement covariance
        :var Matrix I: an identity matrix of size equal to dimension of the state vector
        """
        self.A = A
        self.H = H
        self.x = x
        self.P = P
        self.Q = Q
        self.R = R
        self.I = Matrix.identity(max(x.size()))
        self.measurements = None
        self.counter = None
开发者ID:jepio,项目名称:JKalFilter,代码行数:24,代码来源:kfilter.py

示例10: __find_eigenvector

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import identity [as 别名]
 def __find_eigenvector(self, eig_val, prec, relax_coef):
     is_complex = type(eig_val) is complex
     e_lam = Matrix.identity(self.mtrx.size)
     e_lam *= eig_val
     a = GaussMethod.get_inverse_matrix(self.mtrx - e_lam)
     x_prev = Matrix((self.mtrx.size[0], 1))
     if is_complex:
         x_prev.fill(*[complex(random.randint(1, 100), random.randint(1, 100)) for _ in range(x_prev.size[0])])
     else:
         x_prev.fill(*[random.randint(1, 100) for _ in range(x_prev.size[0])])
     x_cur = (a * x_prev).normalize()
     # method does not always converge,
     # so use successive over-relaxation (SOR) method
     relax_coef *= 0.1
     while (x_cur - x_prev).norm_inf() > prec:
         x_prev = x_cur
         x_cur = (a * x_prev)
         x_cur *= relax_coef
         tmp_x = x_prev.copy()
         tmp_x *= 1 - relax_coef
         x_cur = x_cur + tmp_x
         x_cur = x_cur.normalize()
     return x_cur
开发者ID:kri-k,项目名称:Numerical_methods,代码行数:25,代码来源:qr_eigenvalue_algorithm.py

示例11: solve

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import identity [as 别名]
    def solve(self, precision):
        a_k = self.__mtrx.copy()
        u_k = None
        u = Matrix.identity(self.__mtrx.size)
        prec_func = JacobiEigenvalueAlgorithm.__get_precision
        iter_count = 0

        if self.need_logging:
            print("Solve with precision =", precision)
            print("A0 = ")
            print(a_k)
            print("precision =", prec_func(a_k), "\n")

        while prec_func(a_k) > precision:
            row, col = self.__find_max_above_diagonal(a_k)

            if self.need_logging:
                print("max element of A{0} is A[{1}][{2}] = {3}\n".format(iter_count, row+1, col+1, a_k[row][col]))

            u_k = JacobiEigenvalueAlgorithm.__get_rotation_matrix(a_k, row, col)
            u = u * u_k
            a_k = u_k.transpose() * a_k * u_k
            iter_count += 1

            if self.need_logging:
                print("U{} = ".format(iter_count - 1))
                print(u_k)
                print("A{} = ".format(iter_count))
                print(a_k)
                print("precision =", prec_func(a_k), "\n")

        if self.need_logging:
            print("U = ")
            print(u)
            print("Number of iterations =", iter_count, "\n")

        return a_k, u
开发者ID:kri-k,项目名称:Numerical_methods,代码行数:39,代码来源:jacobi_eigenvalue_algorithm.py

示例12:

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import identity [as 别名]
print 'min-max normalized'
print matrix
matrix.normalize_mean()
print 'mean-normalized'
print matrix

print 'max'
print matrix.max()
print 'min'
print matrix.min()

print 'size'
print matrix.size()

print 'identity'
print Matrix.identity(5)
print -Matrix.identity(5)

print 'zeros'
print Matrix.zeros(2,3)
print 'ones'
print Matrix.ones(3,2)

print 'equal?'
print Matrix.ones(3,3) == Matrix.zeros(3,3)
print Matrix.ones(3,3) == Matrix.ones(3,3)

print 'not equal?'
print Matrix.ones(3,3) != Matrix.ones(3,3)

开发者ID:khiner,项目名称:simple_matrix,代码行数:31,代码来源:matrix_test.py

示例13: testIdentityMatrix

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import identity [as 别名]
 def testIdentityMatrix(self):
     self.assertEquals(
         Matrix([1, 0, 0], [0, 1, 0], [0, 0, 1]),
         Matrix.identity(3))
开发者ID:svinepels,项目名称:Python,代码行数:6,代码来源:matrix_test.py

示例14: Transform

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import identity [as 别名]
class Transform(object):
    # Constructor
    def __init__(self):
        self.edge = Matrix()
        self.master = Matrix()
        self.master.identity()

    # Read Script
    def read_script(self, filename):
        # Initial Start
        f = open(filename, "r")

        # Get Lines
        self.lines = f.read().split("\n")

        # Close File
        f.close()

        # Action
        while ( len( self.lines ) != 0 ):
            if self.lines[0] == "l":               # Add a line
                self.add_edge()
            elif self.lines[0] == "i":             # Set master to identity
                self.lines.pop(0)
                self.master.identity()
            elif self.lines[0] == "s":             # Scale
                self.scale()
            elif self.lines[0] == "t":             # Translation
                self.translate()
            elif self.lines[0] == "x":             # Rotate along x-axis
                self.rotate_x()
            elif self.lines[0] == "y":             # Rotate along y-axis
                self.rotate_x()
            elif self.lines[0] == "z":             # Rotate along z-axis
                self.rotate_x()
            elif self.lines[0] == "a":             # Apply MASTER to EDGE
                self.lines.pop(0)
                self.edge.multiply_edge( self.master )
            elif self.lines[0] == "v":             # Display On Scrren
                self.show()
            elif self.lines[0] == "g":             # Save
                self.save()
            else:
                return

    # Add Edge Function
    def add_edge(self):
        self.lines.pop(0)                          # Remove 'l"
        arguments = self.lines.pop(0)              # Get Arguments

        # "Listify" Arguments
        arguments = arguments.split(" ")

        # Setup Pixel
        temp = Pixel()
        temp.set_red_num( int( arguments[6] ) )
        temp.set_green_num( int( arguments[7] ) )
        temp.set_blue_num( int( arguments[8] ) )

        # Edit edge matrix
        self.edge.add_edge( int( arguments[0] ),
                            int( arguments[1] ),
                            int( arguments[2] ),
                            int( arguments[3] ),
                            int( arguments[4] ),
                            int( arguments[5] ),
                            temp )

    # Scale Function
    def scale(self):
        self.lines.pop(0)                          # Remove 'l"
        arguments = self.lines.pop(0)              # Get Arguments

        # "Listify" Arguments
        arguments = arguments.split(" ")

        # Create Scale Matrix
        temp = Matrix()
        temp.scale( float( arguments[0] ),
                    float( arguments[1] ),
                    float( arguments[2] ) )

        # Apply to MASTER matrix
        self.master.multiply_forwards(temp)

    # Translate Function
    def translate(self):
        self.lines.pop(0)                          # Remove 'l"
        arguments = self.lines.pop(0)              # Get Arguments
        
        # "Listify" Arguments
        arguments = arguments.split(" ")

        # Create Translation Matrix
        temp = Matrix()
        temp.translation( float( arguments[0] ),
                          float( arguments[1] ),
                          float( arguments[2] ) )

        # Apply to MASTER matrix
#.........这里部分代码省略.........
开发者ID:Zilby,项目名称:Stuy-Stuff,代码行数:103,代码来源:transform.py


注:本文中的matrix.Matrix.identity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。