# Wrong solution by lstsq()?

**URL:** <https://discuss.pytorch.org/t/wrong-solution-by-lstsq/125780>\
**Category:** autograd\
**Created:** [July 4, 2021, 6:43pm UTC](https://discuss.pytorch.org/t/wrong-solution-by-lstsq/125780 "2021-07-04T18:43:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Babaki](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/babaki/32/39936_2.png) [@Babaki](https://discuss.pytorch.org/u/Babaki)\
**Post date:** [July 4, 2021, 6:43pm UTC](https://discuss.pytorch.org/t/wrong-solution-by-lstsq/125780/1 "2021-07-04T18:43:38Z")

</div>

The solution that I obtain from `torch.linalg.lstsq(A, B)` is different from what I obtain using `numpy.linalg.lstsq(A, B)`. More importantly, the value of the objective function for the former solution is significantly larger than the latter.

Moreover, in numpy I obtain the same solution using `numpy.linalg.lstsq(A, B)` and `numpy.linalg.pinv(A) @ B`. The solution obtained by `torch.pinverse(A) @ B` is closer to the numpy solution, but also different from the one obtained by `torch.linalg.lstsq(A, B)`.

Does this mean that `torch.linalg.lstsq()` is providing wrong solutions?

This [gist](https://gist.github.com/Behrouz-Babaki/c3db95c00ca61d9ad3a92a9528c8930b) contains the data and scripts that demonstrate this inconcictency.
