Change that: @everywhere function mutate(selectedplayers, positionvectorslist,…
- User
Change that: @everywhere function mutate(selected_players, position_vectors_list, probability) selected_players_matrix = copy(selected_players)
function select_random_player(idx_list, selected_players) while true random_idx = rand(idx_list) if ismissing(selected_players) || !(random_idx in selected_players) return random_idx end end end for i in 1:size(selected_players_matrix)[1] for pos_idx in 1:length(position_vectors_list) if rand() <= probability selected_players_matrix[i, pos_idx] = select_random_player(position_vectors_list[pos_idx], selected_players_matrix[i, :]) end end end return selected_players_matrixend so it would fit a DataFrame with 1 column containing vectors.
- Assistant
You can modify the function like below to make it fit a DataFrame with 1 column containing vectors:
@everywhere function mutate(df, position_vectors_list, probability) selected_players_matrix = copy(df[!, 1]) function select_random_player(idx_list, selected_players) while true random_idx = rand(idx_list) if ismissing(selected_players) || !(random_idx in selected_players) return random_idx end end end for i in 1:length(selected_players_matrix) for pos_idx in 1:length(position_vectors_list) if rand() <= probability selected_players_matrix[i][pos_idx] = select_random_player(position_vectors_list[pos_idx], selected_players_matrix[i]) end end end df[!, 1] = selected_players_matrix return df endNow the function takes a DataFrame
dfas the first argument, and modifies it directly. Before running the loop, we copy the content of the first column inselected_players_matrixvariable. And we replace the for-loop for loop for dimension/size of the matrix with just the length of selected_players_matrix array. Lastly, we modify the contents of the first column ofdfwith the new contents ofselected_players_matrix.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.