Cha*_*nde 5 python numpy matrix seaborn
我有来自 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
Run Code Online (Sandbox Code Playgroud)
如何实现反转,下三角形的掩码?
只需替换triu_indices_from为tril_indices_from:
mask = np.zeros_like(corr, dtype=np.bool)
mask[np.tril_indices_from(mask)] = True
Run Code Online (Sandbox Code Playgroud)