简体   繁体   中英

AttributeError: 'float' object has no attribute 'shape'

I'm trying to get the solution(W2) of a equation, which include np.cov, using python sympy.Solvers, but get a AttributeError: 'float' object has no attribute 'shape'.

在此处输入图片说明

在此处输入图片说明

np.cov with 2 1d arrays works:

In [202]: np.cov(np.arange(10),np.arange(10))
Out[202]: 
array([[9.16666667, 9.16666667],
       [9.16666667, 9.16666667]])

But if one of the arrays is object dtype, I get your error:

In [203]: np.cov(np.arange(10),np.arange(10).astype(object))
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-203-db3c70a7640d> in <module>()
----> 1 np.cov(np.arange(10),np.arange(10).astype(object))

/usr/local/lib/python3.6/dist-packages/numpy/lib/function_base.py in cov(m, y, rowvar, bias, ddof, fweights, aweights)
   2300             w *= aweights
   2301 
-> 2302     avg, w_sum = average(X, axis=1, weights=w, returned=True)
   2303     w_sum = w_sum[0]
   2304 

/usr/local/lib/python3.6/dist-packages/numpy/lib/function_base.py in average(a, axis, weights, returned)
    389 
    390     if returned:
--> 391         if scl.shape != avg.shape:
    392             scl = np.broadcast_to(scl, avg.shape).copy()
    393         return avg, scl

AttributeError: 'float' object has no attribute 'shape'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM