In Python 3.6 using NumPy I have two integer values x,y
, two arrays rho_values, theta_values
and an equation rho = x*sin(theta) + y*cos(theta)
.
I want to find all pairs of (rho, theta)
with rho
in rho_values
and theta
in theta_values
which satisfy the equation.
According to this I came up with the following solution which I expected to give me a boolean matrix with true on every (rho,theta)
index if rho, theta
solve the equation:
diag = np.linalg.norm((256,400)) # Length of diagonal for some image shape (256,400)
theta_bins = np.linspace(-np.pi / 2, np.pi / 2, 300)
rho_bins = np.linspace(-diag, diag, 300)
def solve(x, y):
return rho_bins == y*np.sin(theta_bins[:,np.newaxis])+x*np.cos(theta_bins[:,np.newaxis])
for x in range(0, 255):
for y in range(0, 399):
print(solve(x,y))
It does not work. What would be a correct and fast way to do this? Iterating over both arrays is not an option for me since I have many x,y
values for each of which iterating over both arrays would cost a lot of time.