TypeError: can only be called with ndarray object

147 views
Skip to first unread message

Wendell

unread,
Apr 8, 2021, 7:45:49 PM4/8/21
to cvxpy
Hi!

When I tried the example code:
import cvxpy as cp 
import numpy as np 
# Generate data. 
m = 20 
n = 15 
np.random.seed(1) 
A = np.random.randn(m, n) 
b = np.random.randn(m) 

# Define and solve the CVXPY problem. 
x = cp.Variable(n) 
cost = cp.sum_squares(A @ x - b) 
prob = cp.Problem(cp.Minimize(cost)) 
prob.solve() 

# Print result. 
print("\nThe optimal value is", prob.value) 
print("The optimal x is") 
print(x.value) 
print("The norm of the residual is ", cp.norm(A @ x - b, p=2).value)

I received an error: 
File "D:\anaconda\envs\lib\site-packages\cvxpy\cvxcore\python\canonInterface.py", line 348, in get_problem_matrix
    tensor_J[param_id][i]*constr_length)

TypeError: can only be called with ndarray object

How to solve this? I 
Reply all
Reply to author
Forward
0 new messages