我有来自 seaborn 文档的这段代码,用于为给定相关矩阵的上三角形生成一个掩码
# Compute the correlation matrix
corr = d.corr()
# Generate a mask for the upper triangle
mask = np.zeros_like(corr, dtype=np.bool)
mask[np.triu_indices_from(mask)] = True
如何实现反转,下三角形的掩码?
最佳答案
只需更换 triu_indices_from
与 tril_indices_from
:
mask = np.zeros_like(corr, dtype=np.bool)
mask[np.tril_indices_from(mask)] = True
关于Python为矩阵的下三角生成掩码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53822194/