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

  • Home
  • SEARCH
  • 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 8743275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:38:50+00:00 2026-06-13T11:38:50+00:00

I am trying to plot some data and I am getting this error from

  • 0

I am trying to plot some data and I am getting this error from the noted line. I googled the line but couldn’t find any meaningful discussion on this issue. I am new to Python so trying to figure this stuff out as I go along.

 pl.figure()
 ax = pl.subplot(111)
 ax.plot(Xk[:,0], Xk[:,1], '.')

 ERROR=>>> twos = (y == 2).nonzero()[0]
 for i in twos:
    imagebox = OffsetImage(X[i,:].reshape(28,28))
    location = Xk[i,0], Xk[i,1]
    ab = AnnotationBbox(imagebox, location, boxcoords='data', pad=0.)
    ax.add_artist(ab)

 pl.show()

This is the error message

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

Any clues, seems like y may not be a comparable entity.

I am trying to massage code from a sample file to get my own stuff going so forgive if this is a bit redundant.

I do appreciate the help.

  • 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-13T11:38:50+00:00Added an answer on June 13, 2026 at 11:38 am

    You are trying to assign something to a varaible calles twos:

    twos = (y == 2).nonzero()[0]
    

    An Python tells you (y == 2) has no such property. And that is logic, because the
    brackets cause the evaluation of the expression y == 2 which can be either True or False.

    In python using . means you are trying to access a method or a property of some instance.
    If you a string it has methods bounded to it, that all strings have:

    In [133]: A='lorem ipsum'
    # pressed Tab
    In [134]: A.
    A.capitalize  A.endswith    A.isalnum     A.istitle     A.lstrip      A.rjust       A.splitlines  A.translate
    A.center      A.expandtabs  A.isalpha     A.isupper     A.partition   A.rpartition  A.startswith  A.upper
    A.count       A.find        A.isdigit     A.join        A.replace     A.rsplit      A.strip       A.zfill
    A.decode      A.format      A.islower     A.ljust       A.rfind       A.rstrip      A.swapcase    
    A.encode      A.index       A.isspace     A.lower       A.rindex      A.split       A.title       
    

    If you are new to python, numpy and matplotlib, I recommend you to start using IPython. Your learning of python will be smoother.

    As an alternative to the Tab press you could do dir(someObject):

    In [134]: dir(A)
    Out[134]: 
    ['__add__',
     '__class__',
     '__contains__',
     '__delattr__',
     '__doc__',
     '__eq__',
      .... snipped...
     'startswith',
     'strip',
     'swapcase',
     'title',
     'translate',
     'upper',
     'zfill']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to plot some test data (show at the end of this
I'm using GD to plot some simple charts from array point data.. Trying to
I am trying to plot some categorical data and this answer is very close
I am trying to make a 2D density plot (from some simulation data) with
I'm having some problems trying to plot two different data sets from stdin in
I am trying to plot some data from Flexible Image Transport System (FITS) files,
I'm trying to fit some data to a lognormal distribution and from this generate
I am trying to plot (with Gnuplot) some basic 3d data from one file
I am trying to plot some data using pylab scatter function. I'm using pylab.scatter(X,
I'm trying to plot some data into a histogram using pyplot.hist as such: hst

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.