具有多个元素的数组的真值是不明确的。使用a.any()或a.all()站点

时间:2018-03-13 07:07:12

标签: python numpy

我无法解决此问题。我的输入是交集如下: 在我的输入中我有三个参数,即:

(9.199, -3.81) = Points of intersections 
 9.957 = range
 np.float64(337.5) = angle

所以我必须在元素的基础上过滤元素,如果两个列表输入具有相同的角度,我必须保持其具有较小的范围值。

intersections = [[((9.199, -3.81), 9.957, np.float64(337.5)), ((9.199, -0.0), 9.199, np.float64(360.0))],
                         [((11.941, -4.946), 12.925, np.float64(337.5))]
                         ]

这里我得到了上面提到的错误:      如果t1 [2]不在链中(* filter_values):

Here is my code :
    def filter_and_sort_by_min_range(intersections):
        # for each angle keep the intersection with min range
        filtered_intersections = list()
        filter_values = set()
        data_list = list()

        for data in intersections:
            for val in data:
                data_list.append(val)
        data_list = sorted(data_list, key=lambda x: x[2])
        for i, t1 in enumerate(data_list):
            flag = 0
            for t2 in data_list[i + 1:]:
                if t1[2] == t2[2]:
                    flag = flag + 1
                    if t1[1] < t2[1]:
                        filter_values.add(t1)
                    else:
                        filter_values.add(t2)

            if t1[2] not in  chain(*filter_values):
                filter_values.add(t1)
        filter_values = sorted(filter_values, key=lambda x: x[2])
        filtered_intersections = list(filter_values)
        return filtered_intersections

I am getting below error : 

--------------
Traceback (most recent call last):
  File "D:utils.py", line 294, in test_filter_and_sort_by_min_range_2
    filtered_intersection = filter_and_sort_by_min_range(intersections)
  File "D:utils.py", line 136, in filter_and_sort_by_min_range
    if t1[2] not in  chain(*filter_values):
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Please any suggestions . thanks in advance

0 个答案:

没有答案