0

I have an array like the following and I want to check whether the values in it are in self.pList or not: Here is my point which is an array and I pass it as an argument to addPoint function:

[403.53 273.79]

Here is self.pList:

[array([766.13, 389.14])]

def addPoint(self,point):
        print('self.pList in addPoint')
        print(self.pList)
        if point not in self.pList:
            self.pList.append(point)
            self.X.append(point[0])
            self.Y.append(point[1])

, however it shows me the following error:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

what I have tried is:

def addPoint(self,point):
        print('self.pList in addPoint')
        print(self.pList)
        if point.any() not in self.pList:
            self.pList.append(point)
            self.X.append(point[0])
            self.Y.append(point[1])

also:

def addPoint(self,point):
        print('self.pList in addPoint')
        print(self.pList)
        if point.all() not in self.pList:
            self.pList.append(point)
            self.X.append(point[0])
            self.Y.append(point[1])

But it still has error!

ttina
  • 87
  • 1
  • 9
  • You can refer to this arcticle https://stackoverflow.com/questions/10062954/valueerror-the-truth-value-of-an-array-with-more-than-one-element-is-ambiguous?rq=1 – Md Tausif Jun 19 '22 at 15:49
  • You cannot compare the whole list to the array, try to use a for loop to check for matches –  Jun 19 '22 at 15:52
  • Thank you for your response but those two array are going to have lots of values and if I use a for loop to check, it will take so long time. Is the any more efficient solution for it? – ttina Jun 19 '22 at 19:44

0 Answers0