I am comparing thousands of paths generated by a Monte Carlo simulation stored in `a` to a range of boundary values `x`. Both `a` and `x` are a list of lists. My aim is to know how many paths `a_n` in `a` (with n = 10,000 or more) never drop below each of the boundary values `x1 .... x7`. (Here, `x1 .... x7` are gently upward-sloping straight lines).

Visually, the data looks something like below, where the red line represents one of the boundary values in `x` and the cone of lines represents `a`. (There could be 7 such red lines and I want to know how many of the lines in the cone `a` never drop below each of the red lines in `x`. So an example output of the algorithm could be: `(941, 922, 893, 851, 384, 191)`.)

Currently I am doing this comparison using a list comprehension. However, when the dataset becomes large (say n = 10,000 or more in `a`) this becomes very slow. Is there a computationally more efficient way to achieve the same result?

[![Visual representation of x and a.](https://i.stack.imgur.com/lwlkK.png)](https://i.stack.imgur.com/lwlkK.png)

The code of the list comprehension is shown below.

```
x = [[10, 11], [14, 12]]
a = [[9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16]]

def touch(x, a):
    return [[all([asel > xsubel for xsubel in xel for asel in ael]) for ael in a].count(False) for xel in x ]
touching = touch(x, a)

```

**EDIT**

The result I expect from the simplified example above for `a` and `x` is: `[2, 6]`. I am comparing for every list in `a` and `x`, item 1 in `a` to item 1 in `x`, item 2 in `a` to item 2 in `x`. So: a1\_1 (9) (item 1 in list 1 of a) is lower than x1\_1 (10). a1\_2 (10), is equal to x1\_2 (10) - so that is two violations of the condition. a3\_1 (11) > x1\_1 (10) and a3\_2 (12) > x1\_2 (11) and the other lists in a are also higher than their corresponding elements. For x2 (2nd list in x):, all lists in a are lower except a7, in which a7\_1 (15) is higher than x2\_1 and a7\_2 is higher than x2\_2. Hence `[2, 6]`.