https://blog.csdn.net/Mr_Pend/article/details/120176280
from sklearn.datasets import make_blobs
import matplotlib.pyplot as plt
centers = [[1, 1], [-1, -1], [1, -1]]
X, labels_true = make_blobs(n_samples=10, centers=centers, cluster_std=0.7,random_state=170)
my_members = [True,False,True,True,True,False,False,True,True,True]
col = '#4EACC5'
print(X[:,0].ndim,X[:,0].shape)
fig = plt.figure(figsize=(8, 3))
fig.subplots_adjust(left=0.02, right=0.98, bottom=0.05, top=0.9)
ax = fig.add_subplot(1,2,1)
ax.plot(X[:,0],X[:,1],'w', markerfacecolor=col, marker='.' ,markersize=16)
ax = fig.add_subplot(1,2,2)
# ax.plot(X[:,0][my_members], X[my_members, 1], 'w', markerfacecolor=col, marker='.',markersize=16)
ax.plot(X[my_members,0], X[my_members, 1], 'w', markerfacecolor=col, marker='.',markersize=16)
#X[my_members,0] 等于X[:,0][my_members] ---> 布尔型索引
# plt.scatter(X[:,0],X[:,1])
plt.show()
一个例子 Y = [ [ int(x1+x2 < 1) ] for (x1, x2) in X ]
对X中的每一组元素(x1, x2)遍历一遍,当满足(x1+x2 < 1)时,就把这个布尔值[True]/[False]转换成int型(1或0),存放在[ ]里,作为Y的一个元素。