About python software solve X*log(X/Y) function

Hi, This problem has puzzled me for a long time. About rel_entr() function, in Matlab software Xlog(X/Y) = rel_entr(X,Y),but in python software about Xlog(X/Y), how should I represent it, or in python software rel_entr() function how should I expression it.

This is my codes for this problem

%%

import math
import cvxpy as cvx
import numpy as np

%%

#print(np.log(np.exp(1)))
#print(math.log(1))
#print(cvx.log(1))

%%

Create two scalar optimization variables.

alpha1 = 0.5

alpha2 = 0.5

x = cvx.Variable()
y = cvx.Variable()
#x = cp.Variable()
#y = cp.Variable()

alpha3 = cvx.Variable()

Create two constraints.p

object.is_dcp()

constraints = [x +y ==1]

ans = cvx.rel_entr(2,1)

obj = cvx.Minimize(x*cvx.log(x/y))
#data, chain, inverse_data = obj.get_problem_data(cp.SCS)
obj.is_dcp()

%%

obj.is_dcp(dpp=True)

prob = cvx.Problem(obj, constraints)
prob.solve() # Returns the optimal value.
print(“status:”, prob.status)
print(“optimal value”, prob.value)
print(“optimal var”, x.value, y.value)

Wrong forum but: https://www.cvxpy.org/api_reference/cvxpy.atoms.elementwise.html#kl-div

Hi,Michal_Adamaszek, Thank you very much! My problem has been solved.thanks for your reply

Excuse me, @Michal_Adamaszek. I tried to import library scipy and solve scipy.special.rel_entr(x,y), but I encountered a new problem and this error occurred, "TypeError:Ufunc ‘rel_entr’ not supported for the input types, and the inputs could not be coerced into ced to any supported types according to the casting rule ‘safe’"I am so confused,I think my problem should be solvable.
Here is my modified code:

import math
import cvxpy as cvx
import numpy as np
import scipy

x = cvx.Variable()
y = cvx.Variable()

constraints = [x + y == 1]
obj = cvx.Maximize(scipy.special.rel_entr(x,y)*math.log2(math.exp(1)))

prob = cvx.Problem(obj, constraints)
prob.solve() # Returns the optimal value.
print(“status:”, prob.status)
print(“optimal value”, prob.value)
print(“optimal var”, x.value, y.value)

The bold part is where the error occurred.

https://groups.google.com/g/cvxpy is the appropriate place to seek further assistance for CVXPY difficulties.

This is completely off topic for this forum, so let us stop here. However I just showed you cvxpy.kl_div, you agreed, and now you are instead trying to use a scipy function which is never going to take cvxpy variables as arguments. When you have cvxpy variables you should treat them with cvxpy methods. Over and out.