Split Numpy array with missing ranges as delimiters

Viewed 119

Graph of points, points that have a green line next to them are missing

I have a numpy array which is essentially a contour, a collection of closed x,y points.

It is formatted in this way:

main_array = [[0,0],[2,0],[4,0],[6,0],[0,2],[0,4],[0,6],[2,6],[4,6],[6,6],[6,4],[6,2],[6,0]]

I have another array that states which ranges of values are missing, formatted like this:

missing_point_ranges = [[[2,6],[4,6]],[[6,4],[6,0]]]

  • [2,6] is for x1, y1
  • [4,6] is for x2, y2
  • same case with ([6,4],[6,0]).

Based on those, the objective is to create a new array with multiple dimensions, that uses the missing ranges as delimiters, essentially categorizing the existing points surrounded by missing ranges in separate dimensions.

In this case we would have a new array with two dimensions: One dimension would have only the point [6,6] and the other dimension would have the remaining points.

To specify values for output, it would be as this:

new_array = [[[0,0],[2,0],[4,0],[0,2],[0,4],[0,6]],[6,6]]

0 Answers
Related