def mask_upper_triangle(data): mask = np.zeros_like(data) mask[np.triu_indices_from(mask)] = True data = np.ma.array(data, mask=mask) return data