def extract_off_diag(mtx):
"""
extract off diagonal entries in mtx.
The output vector is order in a column major manner.
:param mtx: input matrix to extract the off diagonal entries
:return:
"""
# we transpose the matrix because the function np.extract will first flatten the matrix
# withe ordering convention 'C' instead of 'F'!!
extract_cond = np.reshape((1 - np.eye(*mtx.shape)).T.astype(bool), (-1, 1), order='F')
return np.reshape(np.extract(extract_cond, mtx.T), (-1, 1), order='F')
评论列表
文章目录