numpy.cov() exception: 'float' object has no attribute 'shape' numpy.cov() exception: 'float' object has no attribute 'shape' numpy numpy

numpy.cov() exception: 'float' object has no attribute 'shape'


The error is reproducible if the array is of dtype=object:

import numpy  as nplabel0 = np.random.random((50, 3)).astype(object)np.cov(label0, rowvar=False)

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

If possible you should convert it to a numeric type. For example:

np.cov(label0.astype(float), rowvar=False)  # works

Note: object arrays are rarely useful (they are slow and not all NumPy functions deal gracefully with these - like in this case), so it could make sense to check where it came from and also fix that.


try

    label0.astype(float32)

and then calculate your cov.

It might because your dtype is object.