def controlled(m):
"""
Make a one-qubit-controlled version of a matrix.
:param m: (numpy.ndarray) A matrix.
:return: A controlled version of that matrix.
"""
rows, cols = m.shape
assert rows == cols
n = rows
I = np.eye(n)
Z = np.zeros((n, n))
controlled_m = np.bmat([[I, Z],
[Z, m]])
return controlled_m
评论列表
文章目录