python: global name not defined [closed] - python

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
So I'm using opencv, numpy, and python for a computer vision project. I'm going off of this tutorial: http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_feature2d/py_features_harris/py_features_harris.html
and have followed it exactly (minus a few minor changes which are apparent in the code). I'm not sure why I'm getting this error (below) and would really appreciate some insight on this. Thanks!
Code:
def applyHarrisCornerDetection():
image1 = cv2.imread('pictures/board1.png')
image2 = cv2.imread('pictures/board2.png')
gray1 = cv2.cvtColor(image1,cv2.COLOR_BGR2GRAY)
gray2 = cv2.cvtColor(image2,cv2.COLOR_BGR2GRAY)
gray1 = np.float32(gray1)
gray2 = np.float32(gray2)
dst1 = cv2.cornerHarris(gray1,2,3,0.04)
dst2 = cv2.cornerHarris(gray2,2,3,0.04)
dst1 = cv2.dilate(dst1,None)
dst2 = cv2.dilate(dst2,None)
img1[dst1>0.01*dst1.max()]=[0,0,255]
img2[dst2>0.01*dst2.max()]=[0,0,255]
cv2.imshow('dst1',img1)
cv2.imshow('dst2',img2)
if cv2.waitKey(0) & 0xff == 27:
cv2.destroyAllWindows()
Error:

It's because of these two lines:
img1[dst1>0.01*dst1.max()]=[0,0,255]
img2[dst2>0.01*dst2.max()]=[0,0,255]
You are assigning elements to some position in a list, but that list hasn't been initialized.

Related

ValueError: not enough values to unpack (expected 2, got 1) using list [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I'm trying to run this code below:
namelist =[[('mixamorig:Head', 'head')],
[('mixamorig:Neck', 'neck_01')]]
for name, newname in namelist:
pb = obj.pose.bones.get(name)
if pb is None:
continue
pb.name = newname
But it gives this error:
for name, newname in namelist:
ValueError: not enough values to unpack (expected 2, got 1)
I've tried to replace the [ with ( or add different enclosures but nothing worked, how can I fix this problem?
This is because you have a list of lists of tuples, not a list of tuples. So you'd need something like:
for item in namelist:
for name, newname in item:
# do something
(or change your data as written in the comment above)

Python 3.0 Pandas converters giving syntax error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I am running Jupyter notebook with Python 3.0 using Pandas to read from an Excel file. I am using a converter to change values in columns i.e. -1 to 1. I keep getting a syntax error in the converters.
import pandas as pd
def convert_adult(cell):
if cell==-1:
return 1
return cell
df = pd.read_excel("Merged.xlsx", "Sheet1", converters = ['adult_not_activation':convert_adult])
return is
File "<ipython-input-17-8eea921e19bb>", line 10
df = pd.read_excel("Merged.xlsx", "Sheet1", converters = ['adult_not_activation':convert_adult])
^
SyntaxError: invalid syntax
I am in the beginning of my journey in Python and Pandas so I hope my problem is not too trivial to ask. Cheers
The error points you to the problem :) You are using a list where a dict is expected.
df = pd.read_excel("Merged.xlsx", "Sheet1", converters = {'adult_not_activation': convert_adult})
converters argument takes a dictionary, You are giving this dictionary as a list but with dictionary syntax.
df = pd.read_excel("Merged.xlsx", "Sheet1", converters = {'adult_not_activation':convert_adult}) # {} instead of []

" Why am I getting a 'DataFrame' object is not callable" error? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
For the first time, I'm unable to use the .shift() method on a column of the DataFrame I'm working with, giving me a DataFrame' object is not callable error.
sdf = quandl.get("AAII/AAII_SENTIMENT", authtoken="mytoken")
sdf = pd.DataFrame(data = sdf)
sdf = sdf.infer_objects()
sdf.index = pd.to_datetime(sdf.index, dayfirst=True)
sdf = sdf.iloc[9:,]
sdf['sp500_2w_future_close'] = sdf(['S&P 500 Weekly Close']).shift(-2)
I was expecting to get a new column displaying S&P 500 Weekly Close two rows down and instead got this weird error. He, p please!

(TypeError: 'float' object is not callable) when doing math [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I am writing a code to calculate all of the energy levels for an electron as it jumps to different orbital levels in the Bohr model. I have some math written, but when I try to run it it says TypeError: 'float' object is not callable. What do I need to do?
Here is my code:
loopone = True
if (work == Element_symbols[0]):
energy = ((charge[0]*(0-13.6))/1)
print ('This is the energy level for the electron at the N=1 state.')
print (energy)
print ('These are all of the possible energies from the n=6 level')
nrgone = (-13.6((1/(5*5)-(1/(6*6)))))
nrgtwo = (-13.6((1/(4*4)-(1/(6*6)))))
nrgthree = (-13.6((1/(3*3)-(1/(6*6)))))
nrgfour = (-13.6((1/(2*2)-(1/(6*6)))))
nrgfive = (-13.6((1/(1*1)-(1/(6*6)))))
Energies = (nrgone, nrgtwo, nrgthree, nrgfour, nrgfive)
print (Energies)
loopone = False
I believe your problem is here
nrgone = (-13.6((1/(5*5)-(1/(6*6)))))
Don't you mean (notice the multiplication sign)?
nrgone = (-13.6*((1/(5*5)-(1/(6*6)))))

does python find errors where there are none? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
while plotting functions with heaviside function I came up with this piece of code, in Idle:
import numpy as np
import matplotlib.pyplot as plt
n_i = [-5, 5]
n = np.linspace(n_i[0], n_i[1], 1E3)
u1 [n+30>=0] = 1
u2 [n-15>=0] =1
u3 = u1 - u2
x = np.sin(2*np.pi*(n/15))*u3
plt.axis([-30,15,-5,5])
plt.xlabel('$n$',fontsize=20)
plt.ylabel('$x(n)$',fontsize=20)
plt.stem(n, x, "--k", linefmt='black', basefmt='black')
plt.grid()
plt.show()
and prior to today, it ran without errors, same with all other of my plots, I've been dealing with python for two years now and throughout classes it had the habit of finding errors where even teachers don't see them. am I missing something here? it says "u1 is not defined", but it is. I even compared with coworkers and classmates alike, haven't seen it put in any other way in the code for the plot. help!
You try to assign a value to u1[...] without even having created u1.
You should init u1 before trying to init its elements.

Categories