IndexError: too many indices for array
OngoingHi! I am currently developing a model using matrices in python and I am keep getting the same error
"IndexError: too many indices for array"
my two variables are are vectors of 3, for example: [1, 2, 3], and my data consist of matrices h and u.
x = model.addMVar((3,), lb=[0, 0, 0])
y = model.addMVar((3,), lb=[0, 0, 0])
Since h is a 3x3 and y is a 1x3 matrix, I needed the transpose of y so I used the following:
y_t = np.transpose(y)
and also computed the transpose of x
x_t = np.transpose(x)
Then, I multiplied both matrices by using:
a = np.dot(h, y_t)
and proceeded with the constraint:
model.addConstr(z[0] <= x_t[0])
model.addConstr(z[1] <= x_t[1])
model.addConstr(z[2] <= x_t[2])
This constraint compares the fist value of x matrix with the first value of the resulting a= (h*y) 3x1 matrix and so on. Nevertheless, I keep getting the same "IndexError: too many indices for array" or if I try to change the variables and create an array for the variables (example: x1 = np.array(y)) I would get an error on the h*y stating "ValueError: shapes (3,3) and (1,) not aligned: 3 (dim 1) != 1 (dim 0)" . I am not sure why I am getting this error since I declared the variable as a 3x1 matrix.
Thank you for any help you can provide me!
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Hi Sab,
There are a few things missing to reproduce your issue. What is \(\texttt{h}\) and \(\texttt{z}\)? Please provide a self-contained minimal working example to make the error reproducible.
Best regards,
Jaromił0
Post is closed for comments.
Comments
2 comments