You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Question: Solve the problem in new versions of np.linalg.solve #26598
Hi, all!
I made a pull-request in statsmodels and my test does not work, where numpy version is --- 2.1.0.dev0. The error occurs in: np.linalg.solve(cm, resid_take).
The dimensions are as follows: cm.shape (200, 5, 5) resid_take.shape (200, 5)
In the error: ValueError: solve: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (m,m),(m,n)->(m,n) (size 200 is different from 5)
I've read here and other places but can't figure out how I need to change the arrays to make the code work in newer versions?
changed the title [-]BUG: <Solve the problem in new versions of np.linalg.solve>[/-][+]BUG: Solve the problem in new versions of np.linalg.solve[/+]on Jun 2, 2024
Looking at (m,m),(m,n)->(m,n) with inputs (200,5,5) and (200,5). The first input is understood as m=5 (the assignment is right-to-left). The second one has m=200, n=5. Since in the first m=5, and in the second m=200, the detection fails.
changed the title [-]BUG: Solve the problem in new versions of np.linalg.solve[/-][+]Question: Solve the problem in new versions of np.linalg.solve[/+]on Jun 2, 2024
No, just reshape it to be (200, 5, 1); that is, make it a stack of explicit 1-column matrices. There is a helpful change note in the docstring explaining what changed in numpy 2.0.
As (I think) we've answered the question and there is no coding change that needs to be made, I am going to close this. Do feel free to continue asking more questions in this closed issue if you need any more clarification, though.
Activity
[-]BUG: <Solve the problem in new versions of np.linalg.solve>[/-][+]BUG: Solve the problem in new versions of np.linalg.solve[/+]mattip commentedon Jun 2, 2024
Looking at
(m,m),(m,n)->(m,n)with inputs (200,5,5) and (200,5). The first input is understood as m=5 (the assignment is right-to-left). The second one has m=200, n=5. Since in the first m=5, and in the second m=200, the detection fails.[-]BUG: Solve the problem in new versions of np.linalg.solve[/-][+]Question: Solve the problem in new versions of np.linalg.solve[/+]quant12345 commentedon Jun 2, 2024
@mattip how to solve this. It is perhaps to swap the axes
a?rkern commentedon Jun 2, 2024
No, just reshape it to be
(200, 5, 1); that is, make it a stack of explicit 1-column matrices. There is a helpful change note in the docstring explaining what changed in numpy 2.0.rkern commentedon Jun 2, 2024
This will work in both 1.x and 2.x numpy builds.
As (I think) we've answered the question and there is no coding change that needs to be made, I am going to close this. Do feel free to continue asking more questions in this closed issue if you need any more clarification, though.
quant12345 commentedon Jun 2, 2024
@rkern @mattip Thank you!
Did this:
ls = np.linalg.solve(cm, resid_take.reshape(200, 5, 1)).reshape(200, 5)