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
🌐
GitHub
github.com › scipy › scipy › issues › 17441
BUG: AttributeError: 'float' object has no attribute 'shape' · Issue #17441 · scipy/scipy
November 18, 2022 - Describe your issue. I tried to plot QQ plot by using stats.probplot, but raised AttributeError. Reproducing Code Example stats.probplot( df['col'], dist="norm", plot=pylab ) pylab.show() Error message AttributeError: 'float' object has ...
Author   bhaskoro-muthohar
Discussions

fitting a single series causing torch to throw 'float' object has no attribute 'shape'
PyTorch-Forecasting version: 0.10.3 PyTorch version: 1.13.1 Python version: 3.8.16 Operating System: Linux 5.10.147 Expected behavior I'm evaluating with DeepAR following the example using a si... More on github.com
🌐 github.com
5
January 7, 2023
AttributeError: 'float' object has no attribute 'shape'
Hello, I had in mind to repeat the GammaPrior example but for other distribution but I face some crashes. I am using JaxNS version 0.0.7 true_mu= 1. true_sigma = 2. def log_likelihood(_myprior, **k... More on github.com
🌐 github.com
3
October 19, 2021
[BUG] 'float' object has no attribute 'shape' in Data pipelines
🐛🐛 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 More on github.com
🌐 github.com
3
December 13, 2020
BUG: <Error in the Numpy 'cov()' function: ' prefix>
Describe the issue: The numpy covariance matrix has a bug as it is saying float has no shape, but why is it calling shape on a float? Reproduce the code example: import numpy as np covariance_matri... More on github.com
🌐 github.com
6
April 4, 2023
🌐
DeepLearning.AI
community.deeplearning.ai › course q&a › natural language processing › nlp with classification and vector spaces
Unit test throwing error on predictions, 'float' object has no attribute 'shape' - NLP with Classification and Vector Spaces - DeepLearning.AI
January 25, 2022 - I have written my predict_tweet function, and the outputs seem to be correct: However, when I run the unit test, I get an error on the unit test itself. Obviously something is wrong on my end, something is not an array when it should be. I have a feeling it is the sigmoid function, which I ...
🌐
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
🌐
GitHub
github.com › Joshuaalbert › jaxns › issues › 40
AttributeError: 'float' object has no attribute 'shape' · Issue #40 · Joshuaalbert/jaxns
October 19, 2021 - AttributeError: 'float' object has no attribute 'shape'#40 · Copy link · Labels · bugSomething isn't workingSomething isn't working · Milestone · Release 1.0 · jecampagne · opened · on Oct 19, 2021 · Issue body actions · Hello, I had in mind to repeat the GammaPrior example but for other distribution but I face some crashes.
Author   jecampagne
🌐
GitHub
github.com › activeloopai › Hub › issues › 316
[BUG] 'float' object has no attribute 'shape' in Data pipelines · Issue #316 · activeloopai/deeplake
December 13, 2020 - Expected behavior/code Data pipelines should be able to process floats without creating a NumPy array. Python version(s): [Clang 11.0.3 (clang-1103.0.32.62)] on darwin ... The problem underlies in setting dynamic shapes.
Author   davidbuniat
🌐
GitHub
github.com › numpy › numpy › issues › 23527
BUG: <Error in the Numpy 'cov()' function: ' prefix> · Issue #23527 · numpy/numpy
April 4, 2023 - Describe the issue: The numpy covariance matrix has a bug as it is saying float has no shape, but why is it calling shape on a float? Reproduce the code example: import numpy as np covariance_matrix = np.cov(data_matrix, rowvar=False) Er...
Author   arnav10goel
Find elsewhere
🌐
YouTube
youtube.com › the python oracle
AttributeError: 'float' object has no attribute 'shape' when using linregress - YouTube
Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn--Music by Eric Matyashttps://www.soundimage.orgTrack title: The Buil
Published   January 22, 2023
Views   369
🌐
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
🌐
Bobby Hadz
bobbyhadz.com › blog › python-attributeerror-float-object-has-no-attribute
AttributeError: 'float' object has no attribute 'X' (Python) | bobbyhadz
The Python "AttributeError: 'float' object has no attribute" occurs when we try to access an attribute that doesn't exist on a floating-point number, e.g.
🌐
freeCodeCamp
forum.freecodecamp.org › python
Bug found in Data Analysis Example B Lecture File - Python - The freeCodeCamp Forum
July 7, 2022 - In the Lecture_2.ipynb example code is: df['rental_gain_return'].mean().round(2) results in: AttributeError: 'float' object has no attribute 'round' This is incorrect and should be: round(df['rental_gain_return'].mean(),2) Same with the median as well. Version of python: 3.10.5 Version of pandas: ...
🌐
GitHub
github.com › apple › coremltools › issues › 424
AttributeError: 'float' object has no attribute 'flatten' · Issue #424 · apple/coremltools
August 20, 2019 - /anaconda3/envs/inpaint-coreml/lib/python3.6/site-packages/coremltools/models/neural_network/builder.py in add_load_constant_nd(self, name, output_name, constant_value, shape) 5311 5312 data = spec_layer_params.data -> 5313 data.floatValue.extend(map(float, constant_value.flatten())) 5314 spec_layer_params.shape.extend(shape) 5315 · AttributeError: 'float' object has no attribute 'flatten' When converting ONNX model to CoreML, encountering this issue ·
Author   edis219
🌐
Reddit
reddit.com › r/learnpython › i get a weird " 'function object has no attribute 'shape' " for a parameter which is clearly not an object, just a numpy array.
r/learnpython on Reddit: I get a weird " 'function object has no attribute 'shape' " for a parameter which is clearly not an object, just a numpy array.
June 27, 2020 -

I'm implementing a cost function for a neural network, which takes in the predictions made on the training set by the forward propagation step, the true output labels Y, and calculates the cost of the model. The function definition is -

def calculate_cost (Y, prediction, activation_output = 'sigmoid'):
    """
    Calculates the cost.

    Takes in the output labels and the prediction from forward propagation, as well as the activation function of the output layer.
    Returns the cost.
    """
    m = Y.shape[1]

    if activation_output.lower() == 'sigmoid':
        cost = (1/m)*np.sum(Y*np.log(prediction) + (1-Y)*np.log(1-prediction))

    if activation_output.lower() == 'softmax':
        cost = (1/m)*np.sum(np.sum(Y*np.log(prediction), axis = 0, keepdims = True))

    return cost

I get an error on the line where I declare m as the second dimension of the input parameter Y.

<ipython-input-6-0c38b0031612> in calculate_cost(Y, prediction, activation_output)     
     10     """
---> 11     m = Y.shape[1]
     12 
     13     if activation_output.lower() == 'sigmoid':

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

Why is this happening? Y is clearly a numpy array.

I am calling a function model() which I have defined which takes in the input data set, the corresponding output labels, and a few hyperparameters and trains the model. This is the function definition for the model() function -

def model (X, Y, architecture, activation_functions, learning_rate = 0.001, print_cost = True, number_of_iterations = 10000):
    """
    Takes in the training set X, the labels Y, and all the required parameters and trains the defined model for the given number of iterations.
    Prints the cost if print_cost is true.
    """
    costs = []
    number_of_layers = len(architecture) - 1

    parameters = initialize_parameters(architecture)

    for i in range(number_of_iterations):

        prediction, cache = forward_propagation(X, parameters, number_of_layers, activation_functions)
        cost = calculate_cost(Y, prediction, activation_functions[-1])

        costs.append(cost)
        gradients = backward_propagation(X, Y, cache, number_of_layers)

        parameters = update_parameters(parameters, number_of_layers, gradients, alpha=0.01)

        if print_cost and i%100 == 0:
            print(f'Completed {i} iterarions.\n')
            print(f'Cost after iteration {i} = {cost}')

    plt.plot(costs)
    plt.xlabel('Iterations (in hundereds)')
    plt.ylabel('Cost')
    plt.title(f'Learning rate = {learning_rate}')
    plt.show()

    print(f'Ran {number_of_iterations} iterations. Returning parameters now.')
    print(f'The final cost of the model was: {costs[-1]}')
    print(f'The training accuracy was: {calculate_accuracy(X, Y, parameters, number_of_layers, activation_functions)}')

    return parameters

I am calling the function like this -

X_train = pd.read_csv('training_set.csv', header = None).to_numpy()
Y_train = pd.read_csv('training_labels.csv', header = None).to_numpy

model(X_train, Y_train, [10,5,5,1], ['relu','relu','relu','relu','sigmoid'])

The second parameter Y_train gets passed to the calculate_cost() function. And Y_train is clearly an array:/

🌐
OpenCV
forum.opencv.org › t › attributeerror-nonetype-object-has-no-attribute-shape › 4910
AttributeError: 'NoneType' object has no attribute 'shape' - imgcodecs - OpenCV
August 24, 2021 - What is this error?? Traceback (most recent call last): File "code.py", line 1717, in shape height, width = input.shape AttributeError: 'NoneType' object has no attribute 'shape' This is the code: input…
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-fix-attributeerror-object-has-no-attribute
How to fix AttributeError: object has no attribute - GeeksforGeeks
July 23, 2025 - To understand this error, we first have to know how to read the error message effectively. It typically consists of two parts: "AttributeError" and "Object has no attribute." The former indicates the type of error, and the latter suggests that the attribute we are trying to access does not exist for the object.
🌐
PyTorch Forums
discuss.pytorch.org › autograd
AttributeError: 'float' object has no attribute 'dtype' when using extra arguments in jacrev() - autograd - PyTorch Forums
March 31, 2023 - Hi, I’m getting an error due to passing an argument (I think its the float k*r_trans) when using extra arguments to the function jacrev(). I tried declaring this as a tensor and then converting it back to a float inside the function pressureSpatialCompRealFunc but then it says the new variable ...
🌐
Bokeh Discourse
discourse.bokeh.org › community support
AttributeError: 'float' object has no attribute 'on_change' - Community Support - Bokeh Discourse
July 19, 2022 - I have 30 lines in one plot and I want to add sliders to change the trends of those lines. I used plot.multi_line to graph out the initial plot. I want to try CustomJS but I need to call my own function deriv1 with solve_ivp to have new y.data but I am not sure how to do so.