I’m new to Python and am struggling to understand how to code this specific situation. I have included an Excel screenshot to better describe the tables and graphs I am working with. From Table 1, column headings 10-13 serve as the x-values. Row # Label provides which row between 1-6 is being affected. Table 2 provides 2 points: A and B. How can we determine which of the 1-6 rows intersect or are above point A? What about for point B?
Logically, I know point A should be at or below all 6 rows and B should be at or below rows 4 and 6. Python should print {1, 2, 3, 4, 5, 6} when asked about A and print {4, 6} when asked about B.
However, how do we translate this process to be done in Python where there are two tables set up just like these?
Table 1 and Table 2
I have tried something like this, but it not working and I think it would only output the total number of rows like 6 for point A and 2 for point B instead of the specific Row # Label that I am looking for as well.
# Iterate through the points in Table #1
for i in range(len(table_one)):
x = table_one[i][0]
y = table_one[i][1]
# Iterate through the matrices in Table #2
for j in range(len(table_two)):
m = table_two[j]
# Calculate the x and y values of the matrix
m_x = np.sum(m, axis=0) * [i]
m_y = np.sum(m, axis=1) * [i]
# Compare the x and y values of the point with those of the matrix
if np.any((np.abs(x - m_x) <= 0.5) & (np.abs(y - m_y) <= 0.5)):
# Increment the counter variable
intersection_count = intersection_count + 1
Lisa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.