Added done Work

This commit is contained in:
2026-02-02 16:52:12 +01:00
parent 573399fa34
commit 02c2773ee7
69 changed files with 625069 additions and 0 deletions

44
read_file.py Normal file
View File

@@ -0,0 +1,44 @@
import numpy as np
def read_xy_file(path):
"""
Reads a 2-column text file and returns x and y arrays.
Assumes the first line is a header.
"""
x_vals = []
y_vals = []
with open(path, "r") as f:
lines = f.readlines()
# Skip header (line 0)
for line in lines[1:]:
if not line.strip():
continue # skip empty lines
parts = line.split()
if len(parts) < 2:
continue # skip malformed lines
x_vals.append(float(parts[0]))
y_vals.append(float(parts[1]))
return x_vals, y_vals
def read_data_with_indices(filename):
"""
Reads a file with one float per line and returns two arrays:
- data_array: the floats from the file
- index_array: the corresponding indices
"""
# Read the data into a numpy array
data_array = np.loadtxt(filename, dtype=float)
# Generate an array of indices
index_array = np.arange(len(data_array))
return data_array, index_array
if __name__ == "__main__":
x, y = read_xy_file("prak2/test.txt")
print(x)
print(y)