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

import numpy  as np

label0 = 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.

Answer from MSeifert on Stack Overflow
🌐
Stack Overflow
stackoverflow.com › questions › 72159124 › attributeerror-float-object-has-no-attribute-reshape
python - "AttributeError: 'float' object has no attribute 'reshape'." - Stack Overflow
Explore Stack Internal ... # similarity matrix sim_mat = np.zeros([len(cleaned_texts), len(cleaned_texts)]) for i in range(len(sentences)): for j in range(len(sentences)): if i != j: sim_mat[i][j] = cosine_similarity(sentence_vectors[i].reshape(1, dim), sentence_vectors[j].reshape(1, dim))[0, 0] sim_mat = np.round(sim_mat, 3) # print(sim_mat) This line sentence_vectors[j].reshape(1, dim))[0, 0] is showing an error: AttributeError: 'float' object has no attribute 'reshape'
🌐
GitHub
github.com › activeloopai › Hub › issues › 316
[BUG] 'float' object has no attribute 'shape' in Data pipelines · Issue #316 · activeloopai/deeplake
December 13, 2020 - 🐛🐛 Bug Report ⚗️ Current Behavior Receive float object has no attribute shape inside data pipelines. Traceback (most recent call last): File "examples/upload_mpi.py", line 52, in res_ds = out_ds.store(tag) File "/Hub/hub/compute...
Author   davidbuniat
🌐
Python Forum
python-forum.io › thread-13879.html
'list' object has no attribute 'reshape'
November 4, 2018 - Hi All, I've just joined this forum, also new to Python, with background in other languages. I've been trying a small piece of code below using jupyter ipython in notebooks.azure.com, the error is coming from the last call for np.reshape function w...
🌐
GitHub
github.com › numpy › numpy › issues › 15587
Some functions raise an unhelpful error when applied to object array · Issue #15587 · numpy/numpy
February 17, 2020 - Traceback (most recent call last): File "object_array.py", line 10, in <module> function(x) File "<__array_function__ internals>", line 6, in cov File "/home/wrzlprmft/.local/lib/python3.7/site-packages/numpy/lib/function_base.py", line 2431, in cov avg, w_sum = average(X, axis=1, weights=w, returned=True) File "<__array_function__ internals>", line 6, in average File "/home/wrzlprmft/.local/lib/python3.7/site-packages/numpy/lib/function_base.py", line 428, in average if scl.shape != avg.shape: AttributeError: 'float' object has no attribute 'shape'
Author   Wrzlprmft
Find elsewhere
🌐
HatchJS
hatchjs.com › home › float object has no attribute ‘shape’: what it means and how to fix it
Float Object Has No Attribute 'Shape': What It Means and How to Fix It
January 5, 2024 - However, there are a few workarounds for this issue, such as converting the float object to an array, using the `shape` attribute of the `parent` object of the float object, or using the `numpy.reshape()` function.
🌐
GitHub
github.com › sktime › pytorch-forecasting › issues › 1220
fitting a single series causing torch to throw 'float' object has no attribute 'shape' · Issue #1220 · sktime/pytorch-forecasting
January 7, 2023 - Getting AttributeError: 'float' object has no attribute 'shape' as I try to fit a simple time series.
Author   soycaporal