本文整理汇总了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)
},
)
示例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)])
示例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
示例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)
示例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
示例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
示例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
示例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
示例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
示例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))
示例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)
示例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])
示例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})
示例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
示例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)