from scipy.optimize import minimize
import numpy as np
matrix = np.array([
[0,1,2,1,2],
[0,1,3,2,3],
[5,2,3,3,5],
[10,3,3,4,12],
[20,5,2,5,15],
[25,8,4,6,20],
[23,7,2,7,18],
[20,6,4,8,16],
[8,4,2,9,12],
[2,1,3,10,8],
[0,1,2,11,4],
[0,1,2,12,3]
])
corrcoef = np.corrcoef(np.transpose(matrix))
relevancy = np.transpose(corrcoef)[0][1:]
#set initial to all dimensions on
x0 = [1,1,1,1]
#minimize the redundancy minus relevancy
fun = lambda x: sum([corrcoef[i+1, j+1] * x[i] * x[j] for i in range(len(x)) for j in range(len(x))]) / (sum(x) ** 2) - (sum(relevancy * x) / sum(x))
res = minimize(fun, x0, bounds=((0,1), (0,1), (0,1), (0,1)))
res.x