Marcelo de Sousa
Marcelo de Sousa

Reputation: 195

'bool' object has no attribute 'shape'

I am training a neural network and a part of my code has returned the following error:

def plot_confusion_matrix(truth,
                          predictions,
                          classes,
                          normalize=False,
                          save=False,
                          cmap=plt.cm.Oranges,
                          path="confusion_matrix.png"):

    acc = (np.array(truth) == np.array(predictions))
    size = float(acc.shape[0]) #error
    acc = np.sum(acc.astype("int32")) / size
    (...)




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

function call

pred = pred.numpy()
plot_confusion_matrix(truth=labels.numpy(),
                      predictions=pred,
                      save=False,
                      path="logref_confusion_matrix.png",
                      classes=["forward", "left", "right"])

Where the thuth represents the labels of Y and predictions the array of prediction, both with shape 32, 3. I checked the update on numpy, ipython etc and all are updated, tried some modification, but without success.

Upvotes: 2

Views: 6519

Answers (1)

cmitch
cmitch

Reputation: 273

The only reason that acc would be a boolean and not a numpy array of booleans is that you are passing in a singular value for truth and predictions. In the code you provided, there would be no error for an actual array of 32x3. Look at the rest of your code and make sure you actually pass in an array to np.array() instead of singular values.

Upvotes: 2

Related Questions