def avg_col(arr, base_check=True, dim_check=False): """Return the arithmetic mean of the given columns (contained subarrays).""" checker = checks.ValidCheck(arr) if not checker.run_checks(base_check, dim_check): return width, height = len(arr), len(arr[0]) avg_arr = [] for y in range(height): temp_arr = [] for x in range(width): temp_arr.append(arr[x][y]) temp_avg = sum(temp_arr) / len(temp_arr) avg_arr.append(temp_avg) return avg_arr
def del_row(arr, row, base_check=True): """Return a new list of lists with the indicated row deleted.""" checker = checks.ValidCheck(arr) if not checker.run_checks(base_check): return width, height = len(arr), len(arr[0]) try: row = int(row) except ValueError: print(f"input row index {row} not coercible to type int. Exiting") return if not 0 <= row < height: print( f"row index {row} is invalid for an input array with {width} columns and {height} rows. Exiting" ) return arr_out = [[] for i in range(width)] for y in range(height): if y != row: arr_row = extractor(arr, y) appender(arr_out, arr_row, deep=False) return arr_out
def extract_row(arr, row, base_check=True): """Return the indicated row (a list of the values at the given index of all subarrays).""" checker = checks.ValidCheck(arr) if not checker.run_checks(base_check): return return extractor(arr, row)
def append_row(arr, row, base_check=True, deep=True): """Return a new list of lists with the indicated row (list) appended.""" checker = checks.ValidCheck(arr) if not checker.run_checks(base_check): return return appender(arr, row, deep)