I am getting name error "NameError: name 'id_count2' is not defined" while calling two functions at a time where the code needs to be corrected this is my code
import numpy as np
op_col = []
for i in df1['Speed']:
op_col.append(i)
np.set_printoptions(threshold=np.inf)
x=np.array([ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8,
14, 14, 14, 14, 11, 11, 8, 11, 12, 14, 9, 8, 13, 15, 7, 11, 13,
11, 1, 1, 0, 0, 13, 9, 14, 8, 9, 10, 19, 8, 11, 11, 13, 16,
8, 0, 0, 7, 14, 15, 12, 8, 0, 10, 9, 8, 0, 0, 9, 9, 7,
7, 11, 13, 12, 11, 7, 12, 16, 16, 15, 0, 0, 8, 13, 12, 10, 10,
10, 11, 13, 14, 7, 11, 13, 17, 8, 8, 9, 9, 10, 7, 7, 9, 10,
8, 9, 10, 7, 8, 7, 10, 10, 12, 13, 9, 8, 12, 9, 0, 0, 0,
0, 0, 11, 11, 14, 9, 16, 26, 23, 9, 16, 19, 7, 0, 2, 0, 12,
16, 15, 16, 17, 15, 12, 12, 15, 21, 25, 27, 26, 26, 27, 27, 28, 7,
10, 12, 14, 17, 0, 0, 0, 10, 10, 12, 7, 12, 16, 20, 18, 7, 18])
x1=x.astype("int32")
x2=x.astype("int32")
def get_count1(id_count1):
x1=x.astype("int32")
sub_lists = np.split(x1, np.where(np.diff(x1)<0)[0] + 1)
id_count1 = 0
id_list1= []
for unit in sub_lists:
if min(unit)<=5 and max(unit) >12 and max(unit) <28 and len(set(unit)) > 1:
id_count1+= 1
id_list1.append(unit)
return id_count1
def get_count2(id_count2):
x2=x.astype("int32")
sub_lists = np.split(x2, np.where(np.diff(x2)<0)[0] + 1)
id_count2 = 0
id_list2= []
for unit in sub_lists:
if min(unit)<=5 and max(unit) >16 and max(unit) <28 and len(set(unit)) > 1:
id_count2+= 1
id_list2.append(unit)
return id_count2
by calling first function get_count1(id_count1)gives me the output calling second function gives error def get_count2(id_count2): NameError: name 'id_count2' is not defined
thanks in adavance
The issue you are encountering is due to the fact that you are trying to pass the variable id_count2 as an argument to the get_count2() function, but it has not been defined yet.
To fix this, you can simply remove id_count2 from the argument list of the get_count2() function.
def get_count2():
x2=x.astype("int32")
sub_lists = np.split(x2, np.where(np.diff(x2)<0)[0] + 1)
id_count2 = 0
id_list2= []
for unit in sub_lists:
if min(unit)<=5 and max(unit) >16 and max(unit) <28 and len(set(unit)) > 1:
id_count2+= 1
id_list2.append(unit)
return id_count2
id_count2 = get_count2()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.