'Python numpy with cvxpy incompatibility issue
I'm trying to run the following code in order to achieve from two vectors A = (N,1) and B = (M,1) a matrix with dimension (N, M). A matrix multiplication should allow to achieve this: AxB. However, my code below throws a strange incompatibility issue:
import pandas as pd
import numpy as np
import cvxpy as cvx
df = pd.DataFrame([
[1,3,1],
[2,0,4],
[0,5,4],
[3,4,3],
[5,2,5]],
columns = ["Metric1","Metric2","Metric3"]
)
mat_bin = df.copy().to_numpy()
v_cvxvar = cvx.Variable(mat_bin.shape[1], nonneg=True)
temp_vect = np.ones(v_cvxvar .shape[0])
eval('( 1.0 / (1.0 - (mat_bin @ v_cvxvar ))) @ temp_vect.T')
- mat_bin is a matrix with dimension (5,3).
- v_cvxvar is a vector with dimension (3,1) (not clear to me if it's a column or row vector)
- mat_bin @ v_cvxvar is a new vector (5,1)
- ( 1.0 / (1.0 - (mat_bin @ v_cvxvar ))) is still a (5,1) vector
- temp_vect.T should be a (1,3) vector
What am I missing? Thank you
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
