Screen Link:
My Code:
def copy_row_k_times(x, row_index, num_copies):
return x[[row_index] * num_copies]
Please can someone explain the logic behind the solution provided above?
Screen Link:
My Code:
def copy_row_k_times(x, row_index, num_copies):
return x[[row_index] * num_copies]
Please can someone explain the logic behind the solution provided above?
First, break the problem down.
[row_index]
?[row_index] * num_copies
be?x[row_index]
be?x[[row_index]]
be?x[[row_index] * num_copies]
be?Think about each individual component, print out values if you can’t figure something out, then think about how it all fits in in relation to indexing. Feel free to ask specific questions if you get stuck.
The intuition behind the operation of duplicating rows is called “broadcasting.”
You can read up on the following