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


Python matutil.listlist2mat函数代码示例

本文整理汇总了Python中matutil.listlist2mat函数的典型用法代码示例。如果您正苦于以下问题:Python listlist2mat函数的具体用法?Python listlist2mat怎么用?Python listlist2mat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: rotation

def rotation(angle):
    angle_degree = angle
    angle_matrix = [[1,0,0],[0, cos(angle_degree), sin(angle_degree)],[0, -sin(angle_degree), cos(angle_degree)]]
    Imatrix = identity(labels = {'x','y','u'})
    list_rc = [(r,c) for r in {'x','y','u'} for c in {'x','y','u'} ]
    mat_angle = listlist2mat(angle_matrix)
    result = Mat((labels, labels), {('u','u'):1, ('x','y'): -sin(angle_degree), ('y','x'): sin(angle_degree), ('x','x'):cos(angle_degree), ('y','y'): cos(angle_degree)})
    return result
    '''
开发者ID:iryek219,项目名称:LinearAlgebra_python,代码行数:9,代码来源:geometry_lab.py

示例2: problem9

def problem9():
    vlist = read_vectors('age-height.txt')
    agelist = []
    heightlist = []
    for v in vlist:
        agelist.append(v['age'])
        heightlist.append(v['height'])
    oneslist = [1] * len(agelist)
    print(agelist)
    print(heightlist)
    colsA = [[a, o] for a, o in zip(agelist, oneslist)]
    A = listlist2mat(colsA)
    print(A)
    b = list2vec(heightlist)
    print(b)
    x = QR_solve(A, b)
    print(x)
    result = A.transpose()*(b-A*x)
    print(result.is_almost_zero())
开发者ID:vvw,项目名称:CodingMatrix,代码行数:19,代码来源:solver_for_p6.py

示例3: listlist2mat

#!/usr/bin/env python3
import sys
from vecutil import list2vec, vec2list
from matutil import listlist2mat
from GF2 import one

golay24mat = listlist2mat([[one, one, 0, 0, 0, one, one, one, 0, one, 0, one],
              [0, one, one, 0, 0, 0, one, one, one, 0, one, one],
              [one, one, one, one, 0, one, one, 0, one, 0, 0, 0],
              [0, one, one, one, one, 0, one, one, 0, one, 0, 0],
              [0, 0, one, one, one, one, 0, one, one, 0, one, 0],
              [one, one, 0, one, one, 0, 0, one, one, 0, 0, one],
              [0, one, one, 0, one, one, 0, 0, one, one, 0, one],
              [0, 0, one, one, 0, one, one, 0, 0, one, one, one],
              [one, one, 0, one, one, one, 0, 0, 0, one, one, 0],
              [one, 0, one, 0, one, 0, 0, one, 0, one, one, one],
              [one, 0, 0, one, 0, 0, one, one, one, one, one, 0],
              [one, 0, 0, 0, one, one, one, 0, one, 0, one, one]])

golay23mat = listlist2mat([[one, one, 0, 0, 0, one, one, one, 0, one, 0],
              [0, one, one, 0, 0, 0, one, one, one, 0, one],
              [one, one, one, one, 0, one, one, 0, one, 0, 0],
              [0, one, one, one, one, 0, one, one, 0, one, 0],
              [0, 0, one, one, one, one, 0, one, one, 0, one],
              [one, one, 0, one, one, 0, 0, one, one, 0, 0],
              [0, one, one, 0, one, one, 0, 0, one, one, 0],
              [0, 0, one, one, 0, one, one, 0, 0, one, one],
              [one, one, 0, one, one, one, 0, 0, 0, one, one],
              [one, 0, one, 0, one, 0, 0, one, 0, one, one],
              [one, 0, 0, one, 0, 0, one, one, one, one, one],
              [one, 0, 0, 0, one, one, one, 0, one, 0, one]])
开发者ID:balr0g,项目名称:encodeframe,代码行数:31,代码来源:encodeframe.py

示例4: module

from vec import Vec
from matutil import listlist2mat
from mat import Mat
from bitutil import noise
from GF2 import one

## Task 1 part 1
""" Create an instance of Mat representing the generator matrix G. You can use
the procedure listlist2mat in the matutil module (be sure to import first).
Since we are working over GF (2), you should use the value one from the
GF2 module to represent 1"""
G = listlist2mat([[one,0,one,one], [one,one,0,one], [0,0,0,one], [one,one,one,0], [0,0,one,0], [0,one,0,0], [one,0,0,0]])
#print(G)

## Task 1 part 2
# Please write your answer as a list. Use one from GF2 and 0 as the elements.
encoding_1001 = G * Vec({0,1,2,3}, {0:one,  3:one})
#print(encoding_1001)


## Task 2
# Express your answer as an instance of the Mat class.
#R = listlist2mat( [[1.0/8,1.0/8,-1.0/4,1.0/8,-1.0/4,-1.0/4,5.0/8],[-1.0/4,1.0/4,0,1.0/4,0,1.0/2,-1.0/4],[1.0/4,-1.0/4,0,1.0/4,1.0/2,0,-1.0/4],[1.0/4,1.0/4,1.0/2,-1.0/4,0,0,-1.0/4]])
R = listlist2mat([[0.125,0.125,-0.25,0.125,-0.25,-0.25,0.625],[-0.25,0.25,0,0.25,0,0.5,-0.25],[0.25,-0.25,0,0.25,0.5,0,-0.25],[0.25,0.25,0.5,-0.25,0,0,-0.25]])
#print(R*G)

## Task 3
# Create an instance of Mat representing the check matrix H.
H = None

## Task 4 part 1
开发者ID:MO2013,项目名称:practice,代码行数:31,代码来源:ecc_lab.py

示例5: QR_factor

from python_lab import dict2list, list2dict

def QR_factor(A):
    col_labels = sorted(A.D[1], key=repr)
    Acols = dict2list(mat2coldict(A),col_labels)
    Qlist, Rlist = aug_orthonormalize(Acols)
    #Now make Mats
    Q = coldict2mat(Qlist)
    R = coldict2mat(list2dict(Rlist, col_labels))
    return Q,R

## 5: (Problem 5) QR factorization of small matrices
#Compute the QR factorization

#Please represent your solution as a list of rows, such as [[1,0,0],[0,1,0],[0,0,1]]
part_1_Q, part_1_R = QR_factor(listlist2mat([[6,6],[2,0],[3,3]]))
part_1_Q = [list(x.f.values()) for x in mat2rowdict(part_1_Q).values()]
part_1_R = [list(x.f.values()) for x in mat2rowdict(part_1_R).values()]
part_2_Q, part_2_R = QR_factor(listlist2mat([[2,3],[2,1],[1,1]]))
part_2_Q = [list(x.f.values()) for x in mat2rowdict(part_2_Q).values()]
part_2_R = [list(x.f.values()) for x in mat2rowdict(part_2_R).values()]

def QR_solve(A, b):
    '''
    Input:
        - A: a Mat with linearly independent columns
        - b: a Vec whose domain equals the set of row-labels of A
    Output:
        - vector x that minimizes norm(b - A*x)
    Note: This procedure uses the procedure QR_factor, which in turn uses dict2list and list2dict.
           You wrote these procedures long back in python_lab.  Make sure the completed python_lab.py
开发者ID:fr05td3su,项目名称:Courses,代码行数:31,代码来源:Orthogonalization_problems.py

示例6: module

from vec import Vec
from mat import Mat
from bitutil import *
from GF2 import one
from matutil import listlist2mat, mat2coldict, coldict2mat

## Task 1 part 1
""" Create an instance of Mat representing the generator matrix G. You can use
the procedure listlist2mat in the matutil module (be sure to import first).
Since we are working over GF (2), you should use the value one from the
GF2 module to represent 1"""
G = listlist2mat([[one,0,one,one],[one,one,0,one], [0,0,0,one], [one, one, one, 0], [0,0,one,0], [0,one,0,0], [one, 0,0, 0]])

## Task 1 part 2
# Please write your answer as a list. Use one from GF2 and 0 as the elements.
encoding_1001 = [0,0,one,one,0,0,one]


## Task 2
# Express your answer as an instance of the Mat class.
R = Mat(({0, 1, 2, 3}, {0, 1, 2, 3, 4, 5, 6}), {(0,6):one, (1,5):one, (2,4):one, (3,2):one})

## Task 3
# Create an instance of Mat representing the check matrix H.
H = listlist2mat([[0,0,0,one,one,one,one],[0,one,one,0,0,one,one],[one,0,one,0,one,0,one]])

## Task 4 part 1
def find_error(e):
    """
Input: an error syndrome as an instance of Vec
Output: the corresponding error vector e
开发者ID:Haretidm,项目名称:Matrix,代码行数:31,代码来源:ecc_lab.py

示例7: Mat

    input: A matrix, M
    outpit: A boolean indicating if M is invertible.

    >>> M = Mat(({0, 1, 2, 3}, {0, 1, 2, 3}), {(0, 1): 0, (1, 2): 1, (3, 2): 0, (0, 0): 1, (3, 3): 4, (3, 0): 0, (3, 1): 0, (1, 1): 2, (2, 1): 0, (0, 2): 1, (2, 0): 0, (1, 3): 0, (2, 3): 1, (2, 2): 3, (1, 0): 0, (0, 3): 0})
    >>> is_invertible(M)
    True

    >>> M1 = Mat(({0,1,2},{0,1,2}),{(0,0):1,(0,2):2,(1,2):3,(2,2):4})
    >>> is_invertible(M1)
    False
    '''
    return rank(list(mat2coldict(M).values())) == len(M.D[0]) == len(M.D[1])

if BOOK_TESTS_ENABLED:
    print("== Test 6.7.12 ==")
    print(is_invertible(listlist2mat([[1, 2, 3], [3, 1, 1]])),
          is_invertible(listlist2mat([[1, 0, 1, 0],
                                      [0, 2, 1, 0],
                                      [0, 0, 3, 1],
                                      [0, 0, 0, 4]])),
          is_invertible(listlist2mat([[1, 0], [0, 1], [2, 1]])),
          is_invertible(listlist2mat([[1, 0], [0, 1]])),
          is_invertible(listlist2mat([[1, 0, 1], [0, 1, 1], [1, 1, 0]])))
    print(is_invertible(listlist2mat([[one, 0, one],
                                      [0, one, one],
                                      [one, one, 0]])),
          is_invertible(listlist2mat([[one, one], [0, one]])))
                        
            

## 10: (Problem 6.7.13) Inverse of a Matrix over GF(2)
开发者ID:HatlessFox,项目名称:SelfStudy,代码行数:31,代码来源:Dimension_problems.py

示例8: mat2rowdict

    assert v.D == M.D[1]
    rd = mat2rowdict(M)
    return Vec(M.D[0], {k: rd[k] * v for k in M.D[0]})


def dot_product_vec_mat_mult(v, M):
    '''
    >>> M2 = listlist2mat([[-5, 10], [-4, 8], [-3, 6], [-2, 4]])
    >>> v3 = Vec({0, 1, 2, 3}, {0: 4, 1: 3, 2: 2, 3: 1})
    >>> dot_product_vec_mat_mult(v3, M2) == Vec({0, 1},{0: -40, 1: 80})
    True
    '''
    assert v.D == M.D[0]
    cd = mat2coldict(M)
    return Vec(M.D[1], {k: v * cd[k] for k in M.D[1]})


if __name__ == '__main__':
    l = [[-1, 1, 2], [1, 2, 3], [2, 2, 1]]
    M = listlist2mat(l)
    v = Vec({0, 1, 2}, {0: 1, 1: 2, 2: 0})
    v2 = lin_comb_mat_vec_mult(M, v)
    M2 = listlist2mat([[-5, 10], [-4, 8], [-3, 6], [-2, 4]])
    v3 = Vec({0, 1, 2, 3}, {0: 4, 1: 3, 2: 2, 3: 1})
    v4 = dot_product_vec_mat_mult(v3, M2)
    A = Mat(({'a', 'b'}, {'@', '#', '?'}),
            {('a', '@'): 2, ('a', '#'): 1, ('a', '?'): 3, ('b', '@'): 20,
             ('b', '#'): 10, ('b', '?'): 30})
    b = Vec({'@', '#', '?'}, {'@': 0.5, '#': 5, '?': -1})
    v5 = lin_comb_mat_vec_mult(A, b)
开发者ID:philiplessner,项目名称:CodingTheMatrix,代码行数:30,代码来源:mvm_problems.py

示例9: squared_Frob

## 1: (Problem 11.8.1) Procedure for computing squared Frobenius norm
def squared_Frob(A):
    '''
    Computes the square of the frobenius norm of A.

    Example:
    >>> squared_Frob(Mat(({1, 2}, {1, 2, 3, 4}), {(1, 1): 1, (1, 2): 2, (1, 3): 3, (1, 4): 4, (2, 1): -4, (2, 2): 2, (2, 3): -1}))
    51
    '''
    return sum(A[(r, c)]**2 for r in A.D[0] for c in A.D[1])



## 2: (Problem 11.8.2) Frobenius_norm_counterexample
#Give a numerical counterxample.
A = listlist2mat([[1, 2, 3], [1, 2, 3]])
Q = listlist2mat([[1, 0], [0, 1], [0, 0]])



## 3: (Problem 11.8.3) Multiplying a vector by a matrix in terms of the SVD of the matrix
# Use lists instead of Vecs
# Part 1
vT_x_1 = [2, 1]
Sigma_vT_x_1 = [4, 1]
U_Sigma_vT_x_1 = [1, 4, 0]

# Part 2
vT_x_2 = [0, 2]
Sigma_vT_x_2 = [0, 2]
U_Sigma_vT_x_2 = [2, 0, 0]
开发者ID:HatlessFox,项目名称:SelfStudy,代码行数:31,代码来源:The_SVD_problems.py

示例10: module

from vec import Vec
from mat import Mat
from bitutil import noise
from GF2 import one

## Task 1 part 1
""" Create an instance of Mat representing the generator matrix G. You can use
the procedure listlist2mat in the matutil module (be sure to import first).
Since we are working over GF (2), you should use the value one from the
GF2 module to represent 1"""
import matutil
G_lists= [[one, 0, one, one],[one, one, 0, one], [0,0,0, one],[one, one, one, 0],[0, 0, one, 0], [0, one, 0, 0],[one, 0, 0, 0]]

G = matutil.listlist2mat(G_lists)

## Task 1 part 2
# Please write your answer as a list. Use one from GF2 and 0 as the elements.
encoding_1001 = [0,0,one,one,0,0,one]


## Task 2
# Express your answer as an instance of the Mat class.
Grev_list2=[[0,0,0,0,0,0,one],[0,0,0,0,0,one,0],[0,0,0,0,one,0,0],[0,0,one,0,0,0,0]]
R = matutil.listlist2mat(Grev_list2)

## Task 3
# Create an instance of Mat representing the check matrix H.
H_list=[[0,0,0,one,one,one,one],[0,one,one,0,0,one,one],[one,0,one,0,one,0,one]]

H = matutil.listlist2mat(H_list)
开发者ID:smokymorgan,项目名称:matrix,代码行数:30,代码来源:ecc_lab.py

示例11: module

from vec import Vec
from mat import Mat
from bitutil import bits2mat, str2bits, noise
from GF2 import one
from matutil import listlist2mat
from matutil import mat2coldict
from matutil import coldict2mat

## Task 1
""" Create an instance of Mat representing the generator matrix G. You can use
the procedure listlist2mat in the matutil module (be sure to import first).
Since we are working over GF (2), you should use the value one from the
GF2 module to represent 1"""
G_list = [[one,0,one,one],[one,one,0,one],[0,0,0,one],[one,one,one,0],[0,0,one,0],[0,one,0,0],[one,0,0,0]]
G = listlist2mat(G_list)

## Task 2
# Please write your answer as a list. Use one from GF2 and 0 as the elements.
encoding_1001 = [0,0,one,one,0,0,one]


## Task 3
# Express your answer as an instance of the Mat class.
Grev_list2=[[0,0,0,0,0,0,one],[0,0,0,0,0,one,0],[0,0,0,0,one,0,0],[0,0,one,0,0,0,0]]
R = listlist2mat(Grev_list2)

## Task 4
# Create an instance of Mat representing the check matrix H.
H_list=[[0,0,0,one,one,one,one],[0,one,one,0,0,one,one],[one,0,one,0,one,0,one]]
H = listlist2mat(H_list)
开发者ID:ashaudupa,项目名称:pythonAlgebra,代码行数:30,代码来源:ecc_lab.py

示例12: module

# Please fill out this stencil and submit using the provided submission script.

from vec import Vec, neg
from mat import Mat
from bitutil import noise
from GF2 import one
import bitutil
import matutil
import vecutil

## Task 1 part 1
""" Create an instance of Mat representing the generator matrix G. You can use
the procedure listlist2mat in the matutil module (be sure to import first).
Since we are working over GF (2), you should use the value one from the
GF2 module to represent 1"""
G = matutil.listlist2mat([[one,0,one,one],[one,one,0,one],[0,0,0,one],[one,one,one,0],[0,0,one,0],[0,one,0,0],[one,0,0,0]])


## Task 1 part 2
# Please write your answer as a list. Use one from GF2 and 0 as the elements.

encoding_1001 = [0,0,one,one,0,0,one]


## Task 2
# Express your answer as an instance of the Mat class.
R = matutil.listlist2mat([[0,0,0,0],[0,0,0,0],[0,0,0,one],[0,0,0,0],[0,0,one,0],[0,one,0,0],[one,0,0,0]]).transpose()
## Task 3
# Create an instance of Mat representing the check matrix H.
H = matutil.listlist2mat([[0,0,0,one,one,one,one],[0,one,one,0,0,one,one],[one,0,one,0,one,0,one]])
开发者ID:omrigildor,项目名称:cs53,代码行数:30,代码来源:ecc_lab.py

示例13: listlist2mat

    output: Inverse of A
    >>> A = listlist2mat([[1, .5, .2, 4],[0, 1, .3, .9],[0,0,1,.1],[0,0,0,1]])
    >>> find_triangular_matrix_inverse(A) == Mat(({0, 1, 2, 3}, {0, 1, 2, 3}), {(0, 1): -0.5, (1, 2): -0.3, (3, 2): 0.0, (0, 0): 1.0, (3, 3): 1.0, (3, 0): 0.0, (3, 1): 0.0, (2, 1): 0.0, (0, 2): -0.05000000000000002, (2, 0): 0.0, (1, 3): -0.87, (2, 3): -0.1, (2, 2): 1.0, (1, 0): 0.0, (0, 3): -3.545, (1, 1): 1.0})
    True
    """
    cd = list()
    label_list = list(mat2rowdict(A).keys())
    rowlist = list(mat2rowdict(A).values())
    for j in label_list:
        c = triangular_solve(rowlist, label_list, list2vec([1 if i == j else 0 for i in label_list]))
        cd.append(c)

    return coldict2mat(cd)


A = listlist2mat([[1, 0.5, 0.2, 4], [0, 1, 0.3, 0.9], [0, 0, 1, 0.1], [0, 0, 0, 1]])
print(
    find_triangular_matrix_inverse(A)
    == Mat(
        ({0, 1, 2, 3}, {0, 1, 2, 3}),
        {
            (0, 1): -0.5,
            (1, 2): -0.3,
            (3, 2): 0.0,
            (0, 0): 1.0,
            (3, 3): 1.0,
            (3, 0): 0.0,
            (3, 1): 0.0,
            (2, 1): 0.0,
            (0, 2): -0.05000000000000002,
            (2, 0): 0.0,
开发者ID:johnmerm,项目名称:matrix,代码行数:31,代码来源:hw5.py

示例14: QR_solve

        >>> x = QR_solve(A, b)
        >>> result = A.transpose()*(b-A*x)
        >>> result.is_almost_zero()
        True
    '''
    Q, R    = QR_factor(A)
    rowlist = [x for x in mat2rowdict(R).values()]
    c       = Q.transpose() * b
    return triangular_solve(rowlist, sorted(A.D[1], key=repr), c)



## 7: (Problem 7) Least Squares Problem
# Please give each solution as a Vec

least_squares_A1 = listlist2mat([[8, 1], [6, 2], [0, 6]])
least_squares_Q1 = listlist2mat([[.8,-0.099],[.6, 0.132],[0,0.986]])
least_squares_R1 = listlist2mat([[10,2],[0,6.08]])
least_squares_b1 = list2vec([10, 8, 6])

x_hat_1 = QR_solve(least_squares_A1, least_squares_b1)

least_squares_A2 = listlist2mat([[3, 1], [4, 1], [5, 1]])
least_squares_Q2 = listlist2mat([[.424, .808],[.566, .115],[.707, -.577]])
least_squares_R2 = listlist2mat([[7.07, 1.7],[0,.346]])
least_squares_b2 = list2vec([10,13,15])

x_hat_2 = QR_solve(least_squares_A2, least_squares_b2)


开发者ID:franzip,项目名称:coursera,代码行数:28,代码来源:Orthogonalization_problems.py

示例15: module

from mat import Mat
from mat import matrix_vector_mul
from bitutil import noise
from bitutil import str2bits, bits2str, bits2mat, mat2bits
from GF2 import one
from matutil import listlist2mat
from matutil import mat2coldict
from matutil import coldict2mat

## Task 1 part 1
""" Create an instance of Mat representing the generator matrix G. You can use
the procedure listlist2mat in the matutil module (be sure to import first).
Since we are working over GF (2), you should use the value one from the
GF2 module to represent 1"""
Gl = [ [ one, 0, one, one ], [ one, one, 0, one ], [ 0, 0, 0, one ], [ one, one, one, 0 ], [ 0, 0, one, 0 ], [ 0, one, 0, 0 ], [ one, 0, 0, 0 ] ]
G = listlist2mat(Gl)

## Task 1 part 2
# Please write your answer as a list. Use one from GF2 and 0 as the elements.
res = G * Vec( {0,1,2,3}, {0:one,1:0,2:0,3:one} )
encoding_1001 = [0, 0, one, one, 0, 0, one]

## Task 2
# Express your answer as an instance of the Mat class.
R = Mat( ( {0,1,2,3}, {0,1,2,3,4,5,6} ), {(0,6): one,(1,5): one,(2,4): one,(3,2): one} )

## Task 3
# Create an instance of Mat representing the check matrix H.
Hl = [ [0,0,0,one,one,one,one], [ 0,one,one,0,0,one,one], [one,0,one,0,one,0,one] ]
H = listlist2mat(Hl)
开发者ID:airy-beam,项目名称:online_courses,代码行数:30,代码来源:ecc_lab.py


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