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

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

我有一个存储 numpy 数组的列表,名为 Triangle

File "main.py", line 63, in triangleCase
    Triangle.remove(OB)
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

我也得到了

AttributeError: 'numpy.ndarray' object has no attribute 'append'

但我无法复制这个

编辑: 函数:

def triangleCase():
  global Triangle, d
  OA = Triangle[-1]
  OB = Triangle[-2]
  OC = Triangle[-3]
  AB = OB - OA
  AO = - OA
  AC = OC - OA
  ABperp = tripleProd(AC,AB,AB) #(AC x AB) x AB
  ACperp = tripleProd(AB,AC,AC) #(AB x AC) x AC
  if dot(ABperp, AO) > 0: #RAB
    Triangle.remove(OC)
    d = ABperp
    return False
  if dot(ACperp,AO) > 0: #RAC
    Triangle.remove(OB)
    d = ACperp
    return False
  return True #RABC

Triangle 和 d 的一个错误值是:

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

Triangle: [array([-17.462565  ,  20.63435875,   0.        ]), array([31.69419203, -2.95257267,  0.        ]), array([ 13.97174987, -18.31107765,   0.        ]), array([-52.2462343 ,  32.56502419,   0.        ]), array([-8.3122833 , 64.51505875,  0.        ]), array([ -4.82763387, -49.86062945,   0.        ])]

d: [  8.3122833  -64.51505875  -0.        ]

根据您的错误,我了解到您尝试使用 remove 从数组中删除一个元素。但是,您不能对数组执行此操作。你需要这样做:

def triangleCase():
  global Triangle, d
  OA = Triangle[-1]
  OB = Triangle[-2]
  OC = Triangle[-3]
  AB = OB - OA
  AO = - OA
  AC = OC - OA
  ABperp = tripleProd(AC,AB,AB)
  ACperp = tripleProd(AB,AC,AC)
  if dot(ABperp, AO) > 0: #RAB
    Triangle.remove(OC)#Triangle=np.delete(Triangle,-3,0)
    d = ABperp
    return False
  if dot(ACperp,AO) > 0: #RAC
    Triangle.remove(OB)#Triangle=np.delete(Triangle,-2,0)
    d = ACperp
    return False
  return True #RABC