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.
You are trying to assign something to a varaible calles
twos:An Python tells you
(y == 2)has no such property. And that is logic, because thebrackets cause the evaluation of the expression
y == 2which can be eitherTrueorFalse.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:
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):