I have a code comprised of two functions one that reads data and the other that counts it. Both functions run properly when run separately, but I get the error when I try to have the counter call the file reader. I would appreciate it if some one could tell me where I am goofing up. Thanks in advance
Error
File "C:\Documents and Settings\Read_File.py", line 50, in counter
Sx = ((25. < Xa) & (Xa < 100.)).sum() #count what is in x range
TypeError: unorderable types: float() < function()
Code
for line in f: #Loop Strips empty lines as well as replaces tabs with space
if line !='':
line = line.strip()
line = line.replace('\t',' ')
columns = line.split()
for line in range(N): #Loop number of lines to be counted
x = columns[8] # assigns variable to columns
y = columns[18]
z = columns[19]
#vx = columns[]
#vy = columns[]
#vz = columns[]
X.append(x)
Y.append(y) #appends data in list
Z.append(z)
Xa = numpy.array(X, dtype=float) #Converts lists to NumPy arrays
Ya = numpy.array(Y, dtype=float)
Za = numpy.array(Z, dtype=float)
return(Xa,Ya,Za) #returns arrays/print statement to test
def counter(Xa):
Sx = ((25. < Xa) & (Xa < 100.)).sum() #count what is in x range
Sy = ((25. < Ya) & (Ya < 100.)).sum() #count what is in y range
Sz = ((25. < Za) & (Za < 100.)).sum() #count what is in z range
return(print(Sx,Sy,Sz))
read_file(F) #function calls
counter(read_file)
EDit
With the help of Lev and James the first problem was fixed now I get this error
Sx = ((2. < Xa) & (Xa < 10.)).sum() #count what is in x range
TypeError: unorderable types: float() < tuple()
Is this because of the commas in the arrays? And if so how can I get around this?
You are trying to call
counter()on the functionread_file(), not on the results of callingread_file(F). You don’t include source forread_file(), but you almost certainly want to do:instead of the last two lines. (By the way, the
result(print(...))incounter()probably doesn’t need thereturnwrapping round the rest of it.)