1
我有這個矩陣的一個二分圖(1和0)和雙簇(行和列的數組陣列)的鄰接矩陣。如何在屬性與matplotlib matshow不同的簇的鄰接矩陣中爲元素(僅1)設置不同的顏色?如何更改matplotlib matshow中某個矩陣元素的顏色?
import numpy as np
import matplotlib.pyplot as plt
a_matrix = np.array([[0, 0, 1, 0, 1], [0, 0, 0, 1, 0], [0, 0, 1, 1, 1], [1, 1, 0, 0, 0], [0, 1, 0, 0 ,0]])
cluster_1 = np.array([[1, 2, 3], [3, 4, 5]])
cluster_2 = np.array([[4, 5], [1, 2]])
# plot matrix with one colour
plt.matshow(a_matrix, cmap='Greys', interpolation='nearest')
鄰接矩陣,雙羣,和二分圖:
謝謝你的回答!有用。順便說一下,我發現sklearn中的笛卡爾產品的實現。 'sklearn.utils.extmath import cartesian' – t1maccapp