简体   繁体   English

np.linalg.lstsq(X,Y)[0] - TypeError: No loop match the specified signature and cast was found for ufunc lstsq_n

[英]np.linalg.lstsq(X,Y)[0] - TypeError: No loop matching the specified signature and casting was found for ufunc lstsq_n

I want to get my X values in the shape [X 1] .我想以[X 1]的形式获得我的 X 值。

For this I am using this code:为此,我正在使用以下代码:

X = np.array([[value,1] for value in X])

I get this warning...我收到这个警告...

/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:2: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray

... but it seemed to work. ......但它似乎工作。

But when I then tried to get m and b values using thgis code:但是当我尝试使用 thgis 代码获取mb值时:

m, b = np.linalg.lstsq(X,Y)[0]

I got this error:我收到了这个错误:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-32-761e189a9409> in <module>()
----> 1 m, b = np.linalg.lstsq(X,Y)[0]

<__array_function__ internals> in lstsq(*args, **kwargs)

/usr/local/lib/python3.6/dist-packages/numpy/linalg/linalg.py in lstsq(a, b, rcond)
   2304         # lapack can't handle n_rhs = 0 - so allocate the array one larger in that axis
   2305         b = zeros(b.shape[:-2] + (m, n_rhs + 1), dtype=b.dtype)
-> 2306     x, resids, rank, s = gufunc(a, b, rcond, signature=signature, extobj=extobj)
   2307     if m == 0:
   2308         x[...] = 0

TypeError: No loop matching the specified signature and casting was found for ufunc lstsq_n

How can I amend my code?如何修改我的代码?

I found a solution.我找到了解决方案。 List comprehension should not be used:不应使用列表推导:

X=np.vstack([df.X,np.ones(len(df.X))]).T

Y = df.Y

m,b = np.linalg.lstsq(X,Y)[0]

This works for me.这对我有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 py.linalg.lstsq 时出错; UFuncTypeError:无法使用转换规则“same_kind”将 ufunc“lstsq_n”输入 0 从 dtype(“O”)转换为 dtype(“float64”) - Error using py.linalg.lstsq; UFuncTypeError: Cannot cast ufunc 'lstsq_n' input 0 from dtype('O') to dtype('float64') with casting rule 'same_kind' Pearsonr:TypeError:没有找到与指定签名匹配的循环,并且为 ufunc add 找到了转换 - Pearsonr: TypeError: No loop matching the specified signature and casting was found for ufunc add 为什么 torch.lstsq 的输出与 np.linalg.lstsq 截然不同? - Why is the output of torch.lstsq drastically different than np.linalg.lstsq? TypeError:没有找到与指定签名匹配的循环,并且为 ufunc greater 找到了转换 - TypeError: No loop matching the specified signature and casting was found for ufunc greater LinAlgError:SVD 未在线性最小二乘 np.linalg.lstsq 中收敛 - LinAlgError: SVD did not converge in Linear Least Squares np.linalg.lstsq Seaborn TypeError: No loop match the specified signature and cast was found for ufunc add when using hue - Seaborn TypeError: No loop matching the specified signature and casting was found for ufunc add when using hue 调用 func pearsonr 和 Got TypeError: 没有找到匹配指定签名和转换的循环用于 ufunc add - Call func pearsonr and Got TypeError: No loop matching the specified signature and casting was found for ufunc add numpy.linalg.lstsq 的向量化 - Vectorisation of numpy.linalg.lstsq 具有固定斜率的linalg.lstsq? - linalg.lstsq with fixed slope? 用numpy linalg lstsq拟合复杂方程的曲线 - curve fitting complicated equation with numpy linalg lstsq
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM