Skills/Error
RuntimeError: Boolean value of Tensor with more than one value is ambiguous
Suyeon Cha
2023. 9. 18. 14:48
728x90
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
해당 에러는 넘파이 배열을 통해 연산을 비교 할 때, True/False로 결과를 말하기 애매할 때 나타나는 오류이다. 뒤에 설명 그대로 .any() 나 all()을 사용하면 명확해진다.
- 모든 값이 같은지 알고 싶다면: all()
- 1개라도 같은지 알고 싶다면: any()
numpy.logical_and(a, b)
대신 이런 코드를 사용해도 된다.
728x90