I tried to rewrite my code into a function. Where I did go wrong? Task: How to swap two…
Jump to turn (8)
- 1I tried to rewrite my code into a function. Where I did go wrong? Task: How to s
- 2By the way, how do you like my code? And, please, add function description and i
- 3Why do we use two levels of brackets here: swappedmatr[[0, 1]] = swappedmatr[[1,
- 4How do you like this function? The task: Find all null (with zeros only) columns
- 5How do you like the if statement here, that I added? if not isinstance(inputlist
- 6How do you like this? Task: Consider the vector, how to build a new vector with
- 7How do you like this? Also add docstring and validation checking. And explain,pl
- 8I still don't understand why do we use axis=-1. Please explain it with different
- User
I tried to rewrite my code into a function. Where I did go wrong? Task: How to swap two rows of a given 2-dim matrix of an array? (in just one step)
My code: two_dim_array = np.random.rand(2,3) print(two_dim_array) two_dim_array[[0, 1]] = two_dim_array[[1, 0]] print(two_dim_array)
Function: def swap_rows_in_2D_matr(matr: np.ndarray) -> np.ndarray: matr[[0, 1]] = matr[[1, 0]]
codereturn matrTests
two_dim_array = np.random.rand(2,3) swapped_array = swap_rows_in_2D_matr(two_dim_array) print(two_dim_array, swapped_array, sep="\n\n")
- Assistant