Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8631305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:12:04+00:00 2026-06-12T09:12:04+00:00

I am using a confusion matrix to measure the performance of my classifier. This

  • 0

I am using a confusion matrix to measure the performance of my classifier. This example would work fine for me (its from here), but I get the whole time TypeError: Invalid dimensions for image data

from numpy import *
import matplotlib.pyplot as plt
from pylab import *

conf_arr = [[50.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [3.0, 26.0, 0.0, 0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0], [4.0, 1.0, 0.0, 5.0, 0.0, 0.0, 0.0], [3.0, 0.0, 1.0, 0.0, 6.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 47.0, 0.0], [2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 8.0]]

norm_conf = []
for i in conf_arr:
        a = 0
        tmp_arr = []
        a = sum(i,0)
        for j in i:
                tmp_arr.append(float(j)/float(a))
        norm_conf.append(tmp_arr)

plt.clf()
fig = plt.figure()
ax = fig.add_subplot(111)
res = ax.imshow(array(norm_conf), cmap=cm.jet, interpolation='nearest')
cb = fig.colorbar(res)
savefig("confmat.png", format="png")

I am new to python and matplotlib. Any help?

Matplot version is 1.1.1. and here is the full traceback:

after res =… I get

TypeError      Traceback (most recent call last)
    C:\Python27\lib\site-packages\SimpleCV\Shell\Shell.pyc in <module>()
    ----> 1 res = ax.imshow(array(norm_conf), cmap=cm.jet, interpolation='nearest')

C:\Python27\lib\site-packages\matplotlib\axes.pyc in imshow(self, X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, shape, filternorm, filter
rad, imlim, resample, url, **kwargs)
   6794                        filterrad=filterrad, resample=resample, **kwargs)
   6795
-> 6796         im.set_data(X)
   6797         im.set_alpha(alpha)
   6798         self._set_artist_props(im)

C:\Python27\lib\site-packages\matplotlib\image.pyc in set_data(self, A)
    409         if (self._A.ndim not in (2, 3) or
    410             (self._A.ndim == 3 and self._A.shape[-1] not in (3, 4))):
--> 411             raise TypeError("Invalid dimensions for image data")
    412
    413         self._imcache =None

TypeError: Invalid dimensions for image data

SimpleCV:105> cb = fig.colorbar(res)

For print norm_conf I get now results: [[1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],...]]. I corrected the indentation problem. But my confusion .png is pretty distorted. Further how should I proceed to label the squares in the matrix?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:12:05+00:00Added an answer on June 12, 2026 at 9:12 am

    This works for me just fine (matplotlib 1.1.1rc). Originally I wanted you to confirm your matplotlib version and post the entire traceback — by “traceback” I mean the few lines before the TypeError line which show what caused the error — and that’s still a good idea, but I think I see what the problem might be.

    This is the error you’d get if norm_conf somehow weren’t being filled (i.e. norm_conf = []):

    Traceback (most recent call last):
      File "mdim2.py", line 19, in <module>
        res = ax.imshow(array(norm_conf), cmap=cm.jet, interpolation='nearest')
      File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 6796, in imshow
        im.set_data(X)
      File "/usr/lib/pymodules/python2.7/matplotlib/image.py", line 411, in set_data
        raise TypeError("Invalid dimensions for image data")
    TypeError: Invalid dimensions for image data
    

    Your code looks like it might have some indentation problems, which often happens when using mixed tabs and spaces. So I’d recommend (1) trying python -tt yourprogramname.py to see if there are whitespace errors, and (2) making sure that you’re using 4-space tabs throughout.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using XNA but it doesn't matter too much for this example. So let's
Some confusion here. Using devise:invitable, and sending emails from heroku with the sendgrid add
I want to plot a confusion matrix using Pylab. The class labels along the
I have a small problem in coding confusion 3x3 matrix by using matlab... I
confusion in using either jax-ws(java) or .NET for implementing the web services. i would
I've been using git but still having confusion about the .gitignore file paths. So,
EDIT Sorry for the confusion, here is my updated question. I am using FindBin
Example code : EDITED : clarified example. Sorry for any confusion. using System.Collections.Specialized; using
Edit I think there is some confusion, I am not using both of the
I'm using coldfusion 9 and I'm trying to grab a file from an ftp

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.