Skip to content

Question: Solve the problem in new versions of np.linalg.solve #26598

@quant12345

Description

@quant12345

Describe the issue:

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?

Reproduce the code example:

https://github.com/statsmodels/statsmodels/pull/9264

Error message:

statsmodels/regression/tests/test_processreg.py:171: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
statsmodels/regression/tests/test_processreg.py:160: in run_formula
    f = preg.fit()
statsmodels/regression/process_regression.py:730: in fit
    f = minimize(
/opt/hostedtoolcache/Python/3.12.3/x64/lib/python3.12/site-packages/scipy/optimize/_minimize.py:722: in minimize
    res = _minimize_powell(fun, x0, args, callback, bounds, **options)
/opt/hostedtoolcache/Python/3.12.3/x64/lib/python3.12/site-packages/scipy/optimize/_optimize.py:3479: in _minimize_powell
    fval = squeeze(func(x))
/opt/hostedtoolcache/Python/3.12.3/x64/lib/python3.12/site-packages/scipy/optimize/_optimize.py:526: in function_wrapper
    fx = function(np.copy(x), *(wrapper_args + args))
statsmodels/regression/process_regression.py:731: in <lambda>
    lambda x: -self.loglike(x),
statsmodels/regression/process_regression.py:563: in loglike
    ls = np.linalg.solve(cm, resid_take)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
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)

Python and NumPy Versions:

Python 3.10.12
NumPy - 2.1.0

Runtime Environment:

No response

Context for the issue:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    33 - QuestionQuestion about NumPy usage or development

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions