Questions about Translating Matlab to Python code

29 views
Skip to first unread message

Siyu Liao

unread,
Jan 7, 2024, 3:32:21 AM1/7/24
to Manopt
Dear community members,

Thank you for taking the time to read this email. As a newcomer to Pymanopt, I am seeking assistance with the task of converting Matlab code to Python, encountering some questions along the way. The original Matlab codes are provided below:

problem.M = complexcirclefactory(N);
problem.cost = @(x) sum_rate_direct(x,A,B,omega,K);
problem.egrad = @(x) sum_rate_direct_egrad(x,A,B,omega,K,N,AA); % notice the 'e' in 'egrad' for Euclidean
options.verbosity=0;
options.stopfun = @mystopfun;
[theta, cost_new, ~, ~] = conjugategradient(problem,theta,options);

where Cost and Euclidean_gradient are self-defined. The python codes I tried are attached and it raises ValueError like this:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

I have reviewed the Cost and Euclidean_gradient functions, and they appear to be correctly defined. Has anyone else encountered a similar issue or can provide guidance on resolving this error?

Thank you for your assistance.

Best regards.




 
PythonCode.jpg
error.jpg

Ronny Bergmann

unread,
Jan 11, 2024, 8:47:32 AM1/11/24
to Manopt

Hi,
I fear I can not help much, since I do not know what your `sum_rate_direct_egrad` returns, but it seems that maybe it should return a number (since you are on the circle if I see corerectly) but it does return a vector?
That way the inner product (computed to obtain df0) might return a vector as well (working element wise on your vector) instead of a number which then leads to exactly an error message as you have.

Maybe that is a good first step to check?
In general it might be easier to post Python questions at https://github.com/pymanopt/pymanopt/issues, that might catch the pymanopt-users attention easier.

Best
Ronny
Reply all
Reply to author
Forward
0 new messages