I have built a program that takes values out of one dataframe, and use these as an input for another dataframe. df_coordinate is a dataframe with rows of x and y coordinates (with sizes between 0 and max_size_x or max_size_y). updated_coordinates is a new dataframe with the size of the screen, that uses the coordinates and a sort of Euclidean distance to make the coordinates represent an area instead of a pixel. The code works as I intend, but right now it is way to slow. I know that vectorizing is much faster, and I try to implement it as much as possible. However, I can't seem to find a way how to vectorize with formulas where the column and row index is used. With .apply I use x.name and x.index as you can see, but is there a way to implement this faster?
max_size_x = 1080
max_size_y = 720
for index, row in df_coordinate.iterrows():
updated_coordinates = pd.DataFrame(np.zeros((max_size_x, max_size_y))) # to do: maybe empty instead of zeroes, and already delete the ones from attention_max
current_time = df_coordinate.loc[index]
coordinate_x = current_time['x_coordinate']
coordinate_y = current_time['y_coordinate']
# calculate area with Euclidean distance:
updated_coordinates = updated_coordinates.apply(lambda x: 1/ ( np.power((np.sqrt(np.power(x.name-coordinate_x,2) + np.power(x.index-coordinate_y,2))),2)))