I have a dataset for different plant species, and I separated each species into a different np.array
.
When trying to generate gaussian models out of these species, I had to calculate the means and covariance matrices for each different label.
The problem is: when using np.cov()
in one of the labels, the function raises the error "'float' object has no attribute 'shape'" and I can't really figure out where the problem is coming from. The exact line of code I'm using is the following:
covx = np.cov(label0, rowvar=False)
Where label0
is a numpy ndarray of shape (50,3), where the columns represent different variables and each row is a different observation.
The exact error trace is:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-81-277aa1d02ff0> in <module>()
2
3 # Get the covariances
----> 4 np.cov(label0, rowvar=False)
C:\Users\Matheus\Anaconda3\lib\site-packages\numpy\lib\function_base.py in cov(m, y, rowvar, bias, ddof, fweights, aweights)
3062 w *= aweights
3063
-> 3064 avg, w_sum = average(X, axis=1, weights=w, returned=True)
3065 w_sum = w_sum[0]
3066
C:\Users\Matheus\Anaconda3\lib\site-packages\numpy\lib\function_base.py in average(a, axis, weights, returned)
1143
1144 if returned:
-> 1145 if scl.shape != avg.shape:
1146 scl = np.broadcast_to(scl, avg.shape).copy()
1147 return avg, scl
AttributeError: 'float' object has no attribute 'shape'
Any ideas of what is going wrong?
try
label0.astype(float32)
and then calculate your cov.
It might because your dtype is object.