from functools import reduce
names = ['Alice', 'Bob', 'Carol', 'David']
interests = [['Football', 'Swimming'], ['Swimming', 'Jooga', 'Jogging'], [
    'Cycling', 'Football'], ['Football', 'Tennis', 'Cycling']]
allinterests = list(set(reduce(lambda x, y: x + y, interests)))
X = scipy.zeros((len(interests), len(allinterests)))
for i, indinterests in enumerate(interests):
    for x in indinterests:
        X[i, allinterests.index(x)] = 1
pylab.matshow(X, interpolation='nearest', cmap=pylab.cm.gray_r)
pylab.show()
pylab.yticks(list(range(len(names))), names)
pylab.ylim([len(names) - 0.5, -0.5])
pylab.xticks(list(range(len(allinterests))), allinterests)
pylab.savefig('interests.png')
График многомерных данных