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


Python matutil.mat2coldict函数代码示例

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


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

示例1: dot_prod_mat_mat_mult

def dot_prod_mat_mat_mult(A, B):
    assert A.D[1] == B.D[0]
    return Mat(
        (A.D[0], B.D[1]),
        {
            (row, col): matutil.mat2rowdict(A)[row] * matutil.mat2coldict(B)[col]
            for row in matutil.mat2rowdict(A)
            for col in matutil.mat2coldict(B)
        },
    )
开发者ID:kenvifire,项目名称:coursera,代码行数:10,代码来源:hw3.py

示例2: find_error_matrix

def find_error_matrix(S):
    """
    Input: a matrix S whose columns are error syndromes
    Output: a matrix whose cth column is the error corresponding to the cth column of S.
    Example:
        >>> S = listlist2mat([[0,one,one,one],[0,one,0,0],[0,0,0,one]])
        >>> find_error_matrix(S)
        Mat(({0, 1, 2, 3, 4, 5, 6}, {0, 1, 2, 3}), {(1, 2): 0, (3, 2): one, (0, 0): 0, (4, 3): one, (3, 0): 0, (6, 0): 0, (2, 1): 0, (6, 2): 0, (2, 3): 0, (5, 1): one, (4, 2): 0, (1, 0): 0, (0, 3): 0, (4, 0): 0, (0, 1): 0, (3, 3): 0, (4, 1): 0, (6, 1): 0, (3, 1): 0, (1, 1): 0, (6, 3): 0, (2, 0): 0, (5, 0): 0, (2, 2): 0, (1, 3): 0, (5, 3): 0, (5, 2): 0, (0, 2): 0})
    """
    return coldict2mat([find_error(mat2coldict(S)[k]) for k in mat2coldict(S)])
开发者ID:fandres70,项目名称:matrix,代码行数:10,代码来源:ecc_lab.py

示例3: is_invertible

def is_invertible(M):
    '''
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
'''
    if M.D[0] != M.D[1]: return False
    if (len(list(mat2coldict(M).values())) == rank(list(mat2coldict(M).values()))):
        return True
    else: return False
开发者ID:trelsco,项目名称:codingthematrix,代码行数:12,代码来源:hw5.py

示例4: Mv_mat_mat_mult

def Mv_mat_mat_mult(A, B):
    assert A.D[1] == B.D[0]
    cols = mat2coldict(B)
    rcols = {}
    for index, col in cols.items():
        rcols[index] = A * col
    return coldict2mat(rcols)
开发者ID:srikanth235,项目名称:Matrix,代码行数:7,代码来源:hw3.py

示例5: dot_product_vec_mat_mult

def dot_product_vec_mat_mult(v, M):
    assert v.D == M.D[0]
    result = Vec(M.D[1], {r: 0 for r in M.D[1]})
    cols = mat2coldict(M)
    for k in M.D[1]:
        result.f[k] = v * cols[k]
    return result
开发者ID:srikanth235,项目名称:Matrix,代码行数:7,代码来源:hw3.py

示例6: lin_comb_mat_vec_mult

def lin_comb_mat_vec_mult(M, v):
    assert M.D[1] == v.D
    result = Vec(M.D[0], {c: 0 for c in M.D[0]})
    cols = mat2coldict(M)
    for k, value in v.f.items():
        result = result + value * (cols[k])
    return result
开发者ID:srikanth235,项目名称:Matrix,代码行数:7,代码来源:hw3.py

示例7: dot_product_vec_mat_mult

def dot_product_vec_mat_mult(v, M):
    assert(v.D == M.D[0])
    res = Vec(M.D[1], {})
    dct = matutil.mat2coldict(M)
    for k,n in dct.items():
        res[k] = n * v
    return res
开发者ID:MO2013,项目名称:practice,代码行数:7,代码来源:hw3.py

示例8: lin_comb_mat_vec_mult

def lin_comb_mat_vec_mult(M, v):
    assert(M.D[1] == v.D)
    res = Vec(M.D[0], {})
    dct = matutil.mat2coldict(M)
    for k in v.D:
        res = res + v[k]*dct[k]
    return res
开发者ID:MO2013,项目名称:practice,代码行数:7,代码来源:hw3.py

示例9: lin_comb_mat_vec_mult

def lin_comb_mat_vec_mult(M, v):
    assert M.D[1] == v.D
    from matutil import mat2coldict

    m = mat2coldict(M)
    y = sum([v[c] * m[c] for c in m.D[1]])
    return y
开发者ID:JamisonWhite,项目名称:coursera_coding_the_matrix,代码行数:7,代码来源:hw3.py

示例10: is_invertible

def is_invertible(M): 
    '''
    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
    '''
    nullspace = solve(M, list2vec([0]))
    ker_zero = nullspace == Vec(nullspace.D, {})

    im_f_eq_codomain = independence.rank(subset_basis(matutil.mat2coldict(M).values())) == len(M.D[1])

    # invertible if its one-to-one, onto, and square matrix
    return ker_zero and im_f_eq_codomain and len(matutil.mat2coldict(M)) == len(matutil.mat2rowdict(M))
开发者ID:buptdjd,项目名称:linearAlgebra-coursera,代码行数:16,代码来源:hw5.py

示例11: dot_prod_mat_mat_mult

def dot_prod_mat_mat_mult(A, B):
    assert A.D[1] == B.D[0]
    import vec, matutil
    A_dict = matutil.mat2rowdict(A)
    B_dict = matutil.mat2coldict(B)
    dp = {(i,j): A_dict[i]*B_dict[j] for j in B_dict.keys() for i in A_dict.keys()}
    return Mat((set(A_dict.keys()), set(B_dict.keys())), dp)
开发者ID:kiori,项目名称:coding_the_matrix,代码行数:7,代码来源:hw3.py

示例12: lin_comb_mat_vec_mult

def lin_comb_mat_vec_mult(M, v):
    assert M.D[1] == v.D
    import matutil
    from matutil import mat2coldict

    mat2col = mat2coldict(M)
    return sum([getitem(v, key) * mat2col[key] for key in v.D])
开发者ID:peachyo,项目名称:codingthematrix,代码行数:7,代码来源:hw3.py

示例13: Mv_mat_mat_mult

def Mv_mat_mat_mult(A, B):
    assert A.D[1] == B.D[0]
#    print (str(A.D) + str(A.f))
#    print (str(B.D) + str(B.f))
#    print('\n')
    colsB = utils.mat2coldict(B)
    return utils.coldict2mat({k:A*colsB[k] for k in colsB})
开发者ID:tri2sing,项目名称:CodingTheMatrix,代码行数:7,代码来源:hw3.py

示例14: lin_comb_mat_vec_mult

def lin_comb_mat_vec_mult(M, v):
    assert(M.D[1] == v.D)


    # vec_list = []
    #
    #
    # col_dict = matutil.mat2coldict(M)
    # for key, val in col_dict.items():
    #     vec_list.append(mult_vec_by_int(val, v[key]))
    #
    # new_v = Vec(M.D[0], {})
    #
    # for vec in vec_list:
    #     new_v += vec
    #
    # return new_v

    new_v = Vec(M.D[0], {})

    col_dict = matutil.mat2coldict(M)

    for key, val in col_dict.items():
        new_v += v[key] * val

    return new_v
开发者ID:buptdjd,项目名称:linearAlgebra-coursera,代码行数:26,代码来源:hw3.py

示例15: mat_move2board

def mat_move2board(Y):
    '''
    Input:
        - Y: a Mat each column of which is a {'y1', 'y2', 'y3'}-Vec
          giving the whiteboard coordinates of a point q.
    Output:
        - a Mat each column of which is the corresponding point in the
          whiteboard plane (the point of intersection with the whiteboard plane 
          of the line through the origin and q).

    Example:
    >>> Y_in = Mat(({'y1', 'y2', 'y3'}, {0,1,2,3}),
         {('y1',0):2, ('y2',0):4, ('y3',0):8,
          ('y1',1):10, ('y2',1):5, ('y3',1):5,
          ('y1',2):4, ('y2',2):25, ('y3',2):2,
          ('y1',3):5, ('y2',3):10, ('y3',3):4})
    >>> print(Y_in)
    
            0  1  2  3
          ------------
     y1  |  2 10  4  5
     y2  |  4  5 25 10
     y3  |  8  5  2  4
    
    >>> print(mat_move2board(Y_in))
    
               0 1    2    3
          ------------------
     y1  |  0.25 2    2 1.25
     y2  |   0.5 1 12.5  2.5
     y3  |     1 1    1    1
    '''
    y_in = mat2coldict(Y)
    y_out = {x:move2board(y_in[x]) for x in y_in.keys()}
    return coldict2mat(y_out)
开发者ID:omrigildor,项目名称:cs53,代码行数:35,代码来源:perspective_lab.py


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