Tbh I’m completely lost so I’m just gonna post all three assignments - any help or input which commands to use will be most appreciated! :
- Create a function called
read_data
, that takes a filename as argument. The function should open the file, and read its contents into a list of list of floats, where the outer list corresponds to the lines of the file, and the inner lists correspond to the columns (that is, convert the strings of each line to a list of two numeric values, and append them to an outer list). The function should return this list. Test the function by calling it on theexperimental_results.txt
file like this:
list_of_rows = read_data(‘experimental_results.txt’)
print(list_of_rows)
- Write a function called
calc_averages
that takes a list of list of floats as input, and calculates the average value for each column by iterating over the rows. The function should return these two values. Test the function by calling it like this:
col1_avg, col2_avg = calc_averages(list_of_rows)
print(col1_avg, col2_avg)
- Write a function called
transpose_data
that turns the list of lists around so that it becomes a list of columns, rather than a list of rows. This means that the outer list now has two elements each containing a list of all the values in the corresponding column. In other words, if I want to access the 26th value in the 2nd column, I would now index with [1][25] instead of [25][1]