I have variable values that the cvxpy has solved. How do I convert D to torch tensor in the following code:
import cvxpy as cp
import numpy as np
import torch
# Problem data.
a = 28
b = 2
c = 1
np.random.seed(1)
X = np.random.randn(a, b)
R = np.random.randn(b, c)
Z = X @ R
Z.shape
# Construct the problem.
D = cp.Variable((c,b))
objective = cp.Minimize(cp.sum_squares(Z*D - X))
constraints = [0 <= D, D <= 1]
prob = cp.Problem(objective, constraints)
prob.solve()
# The optimal objective value is returned by `prob.solve()`.
result = prob.solve()
# The optimal value for x is stored in `x.value`.
print(D.value)
# The optimal Lagrange multiplier for a constraint is stored in
# `constraint.dual_value`.
print(constraints[0].dual_value)