Skip to content

Commit d8277fb

Browse files
Anthony AgbyAnthony Agby
authored andcommitted
add average difference calculation
1 parent b760f3a commit d8277fb

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

HyperSpectral/avgDiffCalculator

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import csv
2+
import os
3+
import re
4+
5+
#Calculates the average difference between corresponding elements of two lists.
6+
def average_difference(list1, list2):
7+
if not list1 or not list2 or len(list1) != len(list2):
8+
return None
9+
10+
differences = [abs(float(x) - float(y[:-2])) for x, y in zip(list1, list2)]
11+
return sum(differences) / len(differences)
12+
13+
#Extracts a specific column from a text file and returns it as a list.
14+
def column_to_list(file_path, column_index, delimiter='|'):
15+
try:
16+
with open("output.txt", 'r') as file:
17+
column_list = []
18+
for line in file:
19+
values = line.strip().split(delimiter)
20+
if column_index < len(values):
21+
column_list.append(values[column_index])
22+
return column_list
23+
except FileNotFoundError:
24+
print(f"Error: File not found at '{file_path}'")
25+
return []
26+
except Exception as e:
27+
print(f"An error occurred: {e}")
28+
return []
29+

0 commit comments

Comments
 (0)