Replace division by zero numpy
This is probably the fastest solution, but the where
function does trigger the error as it precalculates the solutions:
import numpy as np
n = 4
xy = np.random.randint(4, size=(n,n)).astype(float)
x_norm = np.random.randint(4, size=(n,n)).astype(float)
y_norm = np.random.randint(4, size=(n,n)).astype(float)
xy_norm = x_norm*y_norm
edge_map = np.where(xy_norm == 0, xy_norm, xy/xy_norm)
print(xy)
print(xy_norm)
print(edge_map)