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


Python Matrix.transpose方法代码示例

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


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

示例1: perceptronTrain

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import transpose [as 别名]
    def perceptronTrain(self):
        def meanSquare(matrix):
            rows=matrix.rows
            cols=matrix.cols
            a=0
            for i in range(rows):
                for j in range(cols):
                    a=a+matrix[i,j]**2
            a=a**0.5
            return a
        
        

        self.epoch=0
        while not self.testAllDataPass():
            for i in range(len(self.input_data)):
                weight_matrix=Matrix(self.weight)
                bias_matrix=Matrix(self.bias)
                input_matrix=Matrix([self.input_data[i]])
                input_matrix=input_matrix.transpose()
                target_matrix=Matrix([self.output_data[i]])
                target_matrix=target_matrix.transpose()     
                #print "target_matrix:"
                #print target_matrix
                #print 'output_matrix:'
                #print fireForMatrix(self.function_name,weight_matrix*input_matrix+bias_matrix)
                error=target_matrix-fireForMatrix(self.function_name,weight_matrix*input_matrix+bias_matrix)
                #print 'error'+str(error)
                #print 'output'+str(weight_matrix*input_matrix+bias_matrix)
                #print 'after fire output'+str(fireForMatrix(self.function_name,weight_matrix*input_matrix+bias_matrix))
                #print 'target'+str(target_matrix)
                
                #experiment
                self.plot_error.append(meanSquare(error))
                self.plot_target.append(meanSquare(target_matrix))
                self.plot_output.append(meanSquare(fireForMatrix(self.function_name,weight_matrix*input_matrix+bias_matrix)))
                
                
                
                weight_matrix=weight_matrix+error*input_matrix.transpose()
                bias_matrix=bias_matrix+error
                self.weight=convertMatrixToList(weight_matrix)
                self.bias=convertMatrixToList(bias_matrix)
                #print 'weight'+str(self.weight)
                #print 'bias'+str(self.bias)
            self.epoch+=1
        print("Finish Training")
        print("Epoches"+str(self.epoch))
开发者ID:shd101wyy,项目名称:PyNeuron,代码行数:50,代码来源:PerceptronTrainer.py

示例2: main

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import transpose [as 别名]
def main():
    u, v, R = symbols('u v R', real=True)
    xi, eta = symbols(r'\xi \eta', cls=Function)

    numer = 4*R**2
    denom = u**2 + v**2 + numer

    # inverse of a stereographic projection from the south pole
    # onto the XY plane:
    pinv = Matrix([numer * u / denom,
                   numer * v / denom,
                   -(2 * R * (u**2 + v**2)) / denom]) # OK
    if False:
        # textbook style
        Dpinv = simplify(pinv.jacobian([u, v]))
        print_latex(Dpinv, mat_str='pmatrix', mat_delim=None) # OK?

        tDpinvDpinv = factor(Dpinv.transpose() @ Dpinv)
        print_latex(tDpinvDpinv, mat_str='pmatrix', mat_delim=None) # OK

        tDpinvDpinv = tDpinvDpinv.subs([(u, xi(t)), (v, eta(t))])
        dcdt = Matrix([xi(t).diff(), eta(t).diff()])
        print_latex(simplify(
            sqrt((dcdt.transpose() @ tDpinvDpinv).dot(dcdt))))
    else:
        # directly 
        dpinvc = pinv.subs([(u, xi(t)), (v, eta(t))]).diff(t, 1)
        print_latex(sqrt(factor(dpinvc.dot(dpinvc))))
开发者ID:showa-yojyo,项目名称:notebook,代码行数:30,代码来源:stereograph.py

示例3: test_hessenberg

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import transpose [as 别名]
def test_hessenberg():
    A = Matrix([[3, 4, 1],[2, 4 ,5],[0, 1, 2]])
    assert A.is_upper_hessenberg()
    assert A.transpose().is_lower_hessenberg()

    A = Matrix([[3, 4, 1],[2, 4 ,5],[3, 1, 2]])
    assert not A.is_upper_hessenberg()
开发者ID:jegerjensen,项目名称:sympy,代码行数:9,代码来源:test_matrices.py

示例4: tet4

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import transpose [as 别名]
def tet4():
    N1 = z
    N2 = n
    N3 = b
    N4 = 1 - z - n - b

    X = Matrix([[1, x, y, z]])
    X2 = Matrix([[1, x1, y1, z1],
                 [1, x2, y2, z2],
                 [1, x3, y3, z3],
                 [1, x4, y4, z4]])
    N = X * X2.inv()
    N1 = N[0, 0]
    N2 = N[0, 1]
    N3 = N[0, 2]
    N4 = N[0, 3]

    N = Matrix([[N1, 0, 0, N2, 0, 0, N3, 0, 0, N4, 0, 0],
                [0, N1, 0, 0, N2, 0, 0, N3, 0, 0, N4, 0],
                [0, 0, N1, 0, 0, N2, 0, 0, N3, 0, 0, N4]])
    NT = N.transpose()
    #pdV = p*v
    pdV = 3
    factorI = 1
    M = makeM(pdV, NT, factorI, levels=3)
    print "Mtet = \n", M
开发者ID:xirxa,项目名称:pynastran-locr,代码行数:28,代码来源:massMatrix.py

示例5: generate_base_change_matrix

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import transpose [as 别名]
 def generate_base_change_matrix(size = 8):
     ''' Builds the matrix. '''
     if using_sympy:
         A = Matrix([ Polynomial.choose(k).pad_with_zeroes(size)
                                                         for k in range(size) ])
         A = A.transpose()
         Polynomial.base_change_matrix = A.inv()
     elif using_sage:
         print('eh, ill do this later')
     else:
         print('need sympy or sage')
开发者ID:cheyneh,项目名称:polypermclass,代码行数:13,代码来源:polypermclass.py

示例6: quad

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import transpose [as 别名]
    def quad():
        N1 = (1 - z) * (1 - n) / 4
        N2 = (1 + z) * (1 - n) / 4
        N3 = (1 + z) * (1 + n) / 4
        N4 = (1 - z) * (1 + n) / 4

        N = Matrix([[N1, 0, N2, 0, N3, 0, N4, 0], [0, N1, 0, N2, 0, N3, 0, N4]])
        NT = N.transpose()
        pdV = p * A * t / 4  # 4 refers to number of nodes??
        Jacobian = Matrix([[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]])  # not done
        factorI = Jacobian
        M = makeM(pdV, NT, factorI, levels=2)
        print("Mquad = \n", M)
开发者ID:hurlei,项目名称:pyNastran,代码行数:15,代码来源:mass_matrix.py

示例7: test_transpose

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import transpose [as 别名]
def test_transpose():
    M = Matrix([[1,2,3,4,5,6,7,8,9,0],
                [1,2,3,4,5,6,7,8,9,0]])
    assert M.T == Matrix( [ [1,1],
                            [2,2],
                            [3,3],
                            [4,4],
                            [5,5],
                            [6,6],
                            [7,7],
                            [8,8],
                            [9,9],
                            [0,0] ])
    assert M.T.T == M
    assert M.T == M.transpose()
开发者ID:Lucaweihs,项目名称:sympy,代码行数:17,代码来源:test_matrices.py

示例8: calcFeedbackGain

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import transpose [as 别名]
def calcFeedbackGain(A, B, poles):
    n = len(poles)
    param = sp.symbols('s, t1T1, t1T2, t1T3, t1T4')
    s, t1T1, t1T2, t1T3, t1T4 = param
    A
    poly = 1    
    for s_i in poles:
        poly = (s-s_i)*poly
    poly = poly.expand()
    
    p = []
    
    # calculate the coefficient of characteric polynom
    for i in range(n):
#        print i
#        print poly.subs([(s,0)])
        p.append(poly.subs([(s,0)]))
        poly = poly - p[i]
        poly = poly/s
        poly = poly.expand()
    
    
    # calculate controllability matrix
    QsT = Matrix([B.transpose(),\
                 (A*B).transpose(),\
                 (A**2*B).transpose(),\
                 (A**3*B).transpose()])
    Qs = QsT.transpose()
    print 'Qs: ',Qs
    det_Qs = Qs.det()
#    print det_Qs.expand()
    
    
    t1T = Matrix([t1T1, t1T2, t1T3, t1T4])
    
    e_4 = Matrix([[0,0,0,1]])
    
    t1T = e_4*Qs**-1
    
    K = t1T*(A**4 + p[3]*A**(3) + p[2]*A**2 + p[1]*A + p[0]*sp.eye(4))
    return K
开发者ID:cklb,项目名称:pymoskito,代码行数:43,代码来源:linearization_separate.py

示例9: setDefaultLearningRate

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import transpose [as 别名]
    def setDefaultLearningRate(self):
        from sympy import Matrix
        num=len(self.net.input_data)
        sum=Matrix([[0 for column in range(len(self.net.input_data[0]))]for row in range(len(self.net.input_data[0]))])
        for elem in self.net.input_data:
            mat=Matrix([elem])
            mat=mat.transpose()*mat/num
            sum=sum+mat
        eigenvalue=sum.eigenvals()
        max=0
    # print 'sum'
    #print sum
    # print eigenvalue
        for keys in eigenvalue:
            if keys>max:
                max=keys
        self.learning_rate=1/max
    
    

        
开发者ID:shd101wyy,项目名称:PyNeuron,代码行数:19,代码来源:LMSTrainer.py

示例10: main

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import transpose [as 别名]
def main():
    x_1, x_2 = symbols('x_1 x_2', real=True)

    # Phi(x_1, x_2) = a torus.
    Phi = Matrix([(2 + cos(x_2)) * cos(x_1),
                  (2 + cos(x_2)) * sin(x_1),
                  sin(x_2),])
    DPhi = Phi.jacobian([x_1, x_2])
    print_latex(DPhi, fold_func_brackets=True,
        mat_str='pmatrix', mat_delim=None)

    tDPhi = DPhi.transpose()
    print_latex(tDPhi, fold_func_brackets=True,
        mat_str='pmatrix', mat_delim=None)

    tDPhiDPhi = simplify(tDPhi * DPhi) # simplify \sin^2 + \cos^2.
    print_latex(tDPhiDPhi, fold_func_brackets=True,
        mat_str='pmatrix', mat_delim=None)
    dcdt = Matrix([Derivative(xi, t, 1), Derivative(eta, t, 1)])

    print_latex(sqrt((dcdt.transpose() @ tDPhiDPhi).dot(dcdt)),
       fold_func_brackets=True)
开发者ID:showa-yojyo,项目名称:notebook,代码行数:24,代码来源:torus.py

示例11: Rotate

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import transpose [as 别名]
def Rotate( element, theta):     
    """Applies a rotation on any polarizing element given 
    its Jones matrix representation and a angle of rotation.
    The angle is to be ginven in radians and the matrix.  

    Examples for elements to imput are the vertical polarizer 
    and a quarter waveplate:

    V = Matrix([ [ 1 , 0],\
                        [ 0 , 0] ])

    QWP = Matrix([ [ 1 , 0],  \
                            [ 0 , -1j] ])
    """
    from sympy import Matrix, cos, sin

    assert isinstance(element, Matrix)
    assert element.shape == (2,2)
    
    rotator = Matrix([ [ cos(theta),  sin(theta)], \
                                 [-sin(theta), cos(theta) ] ])
    return rotator.transpose() * element * rotator
开发者ID:bebopsan,项目名称:rutinas-calibracion-slm,代码行数:24,代码来源:optimization_routines.py

示例12: testAllDataPass

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import transpose [as 别名]
 def testAllDataPass(self):
     all_pass=True
     weight_matrix=Matrix(self.weight)
     bias_matrix=Matrix(self.bias)
     for i in range(len(self.input_data)):
         input_matrix=Matrix([self.input_data[i]])
         input_matrix=input_matrix.transpose()
         #target_matrix=Matrix([self.output_data[i]])
         #target_matrix=target_matrix.transpose()
         output_matrix=weight_matrix*input_matrix+bias_matrix
         output=[]
         for j in range(len(self.weight)):
             output.append(output_matrix[j,0])
         output=fireForList(self.function_name,output)
         if output!=self.output_data[i]:
             all_pass=False
             #print 'output'+str(output)
             #print 'target'+str(self.output_data[i])                
             break
         #print 'output'+str(output)
         #print 'target'+str(self.output_data[i])
     #print all_pass
     return all_pass
开发者ID:shd101wyy,项目名称:PyNeuron,代码行数:25,代码来源:PerceptronTrainer.py

示例13: TestScrew6

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import transpose [as 别名]
class TestScrew6(unittest.TestCase):
    """Unit test for Screw6 class."""
    def setUp(self):
        # setup data matrices to compare against
        self.data = Matrix([
            [1, 2, 3, 4, 5, 6],
            [7, 8, 9, 10, 11, 12],
            [13, 14, 15, 16, 17, 18],
            [19, 20, 21, 22, 23, 24],
            [25, 26, 27, 28, 29, 30],
            [31, 32, 33, 34, 35, 36]
        ])
        self.data_tl = Matrix([
            [1, 2, 3],
            [7, 8, 9],
            [13, 14, 15]
        ])
        self.data_tr = Matrix([
            [4, 5, 6],
            [10, 11, 12],
            [16, 17, 18]
        ])
        self.data_bl = Matrix([
            [19, 20, 21],
            [25, 26, 27],
            [31, 32, 33]
        ])
        self.data_br = Matrix([
            [22, 23, 24],
            [28, 29, 30],
            [34, 35, 36]
        ])
        # setup Screw6 instances
        self.empty = Screw6()
        self.indiv = Screw6()
        self.indiv.val = self.data

    def test_init(self):
        """Test constructor."""
        # test instance type
        self.assertIsInstance(self.empty, Screw6)
        self.assertIsInstance(self.indiv, Screw6)
        self.assertIsInstance(Screw6(self.data), Screw6)
        self.assertIsInstance(Screw6(value=self.data), Screw6)
        self.assertIsInstance(
            Screw6(
                self.data_tl, self.data_tr,
                self.data_bl, self.data_br
            ), Screw6
        )
        self.assertIsInstance(
            Screw6(
                tl=self.data_tl, bl=self.data_bl,
                tr=self.data_tr, br=self.data_br
            ), Screw6
        )
        # test raise appropriate exception
        self.assertRaises(NotImplementedError, Screw6, 3, 4)
        self.assertRaises(NotImplementedError, Screw6, tl=5, tr=6)

    def test_val(self):
        """Test get and set of val()"""
        # test get
        self.assertEqual(self.empty.val, zeros(6, 6))
        self.assertEqual(self.indiv.val, self.data)
        # test set
        self.indiv.val = self.data.transpose()
        self.assertEqual(self.indiv.val, self.data.transpose())
        with self.assertRaises(ShapeError):
            self.empty.val = Matrix([3, 3])

    def test_topleft(self):
        """Test get and set of topleft()"""
        # test get
        self.assertEqual(self.empty.topleft, zeros(3, 3))
        # test set
        self.indiv.topleft = self.data_tl
        self.assertEqual(self.indiv.topleft, self.data_tl)
        with self.assertRaises(ShapeError):
            self.empty.topleft = Matrix([3, 3])

    def test_topright(self):
        """Test get and set of topright()"""
        # test get
        self.assertEqual(self.empty.topright, zeros(3, 3))
        # test set
        self.indiv.topright = self.data_tr
        self.assertEqual(self.indiv.topright, self.data_tr)
        with self.assertRaises(ShapeError):
            self.empty.topright = Matrix([3, 3])

    def test_botleft(self):
        """Test get and set of botleft()"""
        # test get
        self.assertEqual(self.empty.botleft, zeros(3, 3))
        # test set
        self.indiv.botleft = self.data_bl
        self.assertEqual(self.indiv.botleft, self.data_bl)
        with self.assertRaises(ShapeError):
            self.empty.botleft = Matrix([3, 3])
#.........这里部分代码省略.........
开发者ID:ELZo3,项目名称:symoro,代码行数:103,代码来源:test_screw6.py

示例14: LagrangesMethod

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import transpose [as 别名]

#.........这里部分代码省略.........
        self._term2 = Matrix([])
        self._term3 = Matrix([])
        self._term4 = Matrix([])

        # Creating the qs, qdots and qdoubledots

        q_list = list(q_list)
        if not isinstance(q_list, list):
            raise TypeError('Generalized coords. must be supplied in a list')
        self._q = q_list
        self._qdots = [diff(i, dynamicsymbols._t) for i in self._q]
        self._qdoubledots = [diff(i, dynamicsymbols._t) for i in self._qdots]

        self.coneqs = coneqs

    def form_lagranges_equations(self):
        """Method to form Lagrange's equations of motion.

        Returns a vector of equations of motion using Lagrange's equations of
        the second kind.

        """

        q = self._q
        qd = self._qdots
        qdd = self._qdoubledots
        n = len(q)

        #Putting the Lagrangian in a Matrix
        L = Matrix([self._L])

        #Determining the first term in Lagrange's EOM
        self._term1 = L.jacobian(qd)
        self._term1 = ((self._term1).diff(dynamicsymbols._t)).transpose()

        #Determining the second term in Lagrange's EOM
        self._term2 = (L.jacobian(q)).transpose()

        #term1 and term2 will be there no matter what so leave them as they are

        if self.coneqs is not None:
            coneqs = self.coneqs
            #If there are coneqs supplied then the following will be created
            coneqs = list(coneqs)
            if not isinstance(coneqs, list):
                raise TypeError('Enter the constraint equations in a list')

            o = len(coneqs)

            #Creating the multipliers
            self.lam_vec = Matrix(dynamicsymbols('lam1:' + str(o + 1)))

            #Extracting the coeffecients of the multipliers
            coneqs_mat = Matrix(coneqs)
            qd = self._qdots
            self.lam_coeffs = -coneqs_mat.jacobian(qd)

            #Determining the third term in Lagrange's EOM
            #term3 = ((self.lam_vec).transpose() * self.lam_coeffs).transpose()
            self._term3 = self.lam_coeffs.transpose() * self.lam_vec

            #Taking the time derivative of the constraint equations
            diffconeqs = [diff(i, dynamicsymbols._t) for i in coneqs]

            #Extracting the coeffecients of the qdds from the diff coneqs
            diffconeqs_mat = Matrix(diffconeqs)
开发者ID:abhishekkumawat23,项目名称:sympy,代码行数:70,代码来源:lagrange.py

示例15: xrange

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import transpose [as 别名]
M = [(P[i]*E*Nu[i, :].T)[0].subs({x: R[0], y: R[1]}) for i in xrange(0, len(p))]
#pprint(M)
W = [gradient(M[i], R).to_matrix(R).subs({R[0]: x, R[1]: y})[:2] for i in xrange(len(p))]


# Natural laws transformation calculation

natural_field = diag(*(ones(1, len(p)) * ((Nu*G).multiply_elementwise(F))))

force_is_present = natural_field.applyfunc(
            lambda exp: Piecewise((1.0, exp > 0.0),
                                  (0.0, exp <= 0.0))
        )

natural_influence = (Upsilon * Alpha * natural_field + S * Alpha)*force_is_present*ones(len(fs), 1)
pending_transformation_vector = Omicron.transpose()*natural_influence

#pprint(W, num_columns=1000)
#pprint(Nu)
#pprint(get_matrix_of_converting_atoms(Nu, p, pending_transformation_vector))
#pprint(get_matrix_of_converted_atoms(Nu, p, pending_transformation_vector, natural_influence, Omicron, D))
#pprint(Nu - get_matrix_of_converting_atoms(Nu, p, pending_transformation_vector) + get_matrix_of_converted_atoms(Nu, p, pending_transformation_vector, natural_influence, Omicron, D))

#import parmap

#images = parmap.map(vector_field_to_image, W, (-10, 10, 10, -10))
#image = reduce(alpha_composite, images)

#im = image # vector_field_to_image(W[0], (-10, 10, 10, -10))
#im[:, :, -1] = 0
#mlab_imshowColor(im[:, :, :3])
开发者ID:aloschilov,项目名称:simple-game-engine,代码行数:33,代码来源:work_circle_matrix_form_sympy.py


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