Commit 911e2ccf by Bertrand NÉRON

fix doc in matrix

parent dba0c7b4
 ... @@ -91,18 +91,14 @@ def to_str(matrix): ... @@ -91,18 +91,14 @@ def to_str(matrix): # by design all matrix cols have same size # by design all matrix cols have same size for row in zip(*matrix): for row in zip(*matrix): cells = [str(cell) for cell in row] cells = [str(cell) for cell in row] s += " ".join(cells) + "\n" s += "\t".join(cells) + "\n" return s return s def mult(matrix, val): def mult(matrix, val): """ """ :param matrix: the matrix to compute the size :param matrix: the matrix :type matrix: matrix :type matrix: matrix :param rows_no: the number of rows :type rows_no: int :param col_no: the number of columns :type col_no: int :param val: the value to mult the matrix with :param val: the value to mult the matrix with :type val: int :type val: int :return: a new matrix corresponding the scalar product of matrix * val :return: a new matrix corresponding the scalar product of matrix * val ... @@ -115,6 +111,21 @@ def mult(matrix, val): ... @@ -115,6 +111,21 @@ def mult(matrix, val): return new_matrix return new_matrix def mult_inplace(matrix, val): """ compute the scalar product of a matrix and a value do this operation in place :param matrix: the matrix :type matrix: matrix :param val: the value to mult the matrix with :type val: int """ for col in matrix: for row_nb, cell in enumerate(col): col[row_nb] = cell * val def get_row(matrix, row_no): def get_row(matrix, row_no): """ """ :param matrix: the matrix to compute the size :param matrix: the matrix to compute the size ... @@ -221,8 +232,7 @@ def replace_row(matrix, row_no, row): ... @@ -221,8 +232,7 @@ def replace_row(matrix, row_no, row): for col_no, value in enumerate(row): for col_no, value in enumerate(row): set_cell(matrix, row_no, col_no, value) set_cell(matrix, row_no, col_no, value) if __name__ == '__main__': if __name__ == '__main__': m = create(5, 3) m = create(5, 3) print(m) print(m) ... @@ -233,4 +243,7 @@ if __name__ == '__main__': ... @@ -233,4 +243,7 @@ if __name__ == '__main__': print(to_str(m)) print(to_str(m)) print("get row 0", get_row(m, 0)) print("get row 0", get_row(m, 0)) print("get col 0", get_col(m, 0)) print("get col 0", get_col(m, 0)) m2 = create(3, 2, 4) mult_inplace(m2, 2) print(to_str(m2))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!