[英]Python ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
[英]Python ValueError: The truth value of an array with more than one element is ambiguous. No answer seems to apply to my error
我有錯誤:“ValueError:具有多個元素的數組的真值不明確。在三行中使用 a.any() 或 a.all()”:
col, minimax_score = int(minimax(board, 2, -math.inf, math.inf, True))
,
valid_locations = get_valid_locations(board)
和
if available_square(board, col):
我在 Internet 上搜索了可能的解決方案(例如,使用(ab).any()
或(ab).all()
而不是a and b
),但它們似乎都不適用於我的情況。
編輯:
“minimax” function 很長,所以我將添加以下內容:
def minimax(board, depth, alpha, beta, maximizingPlayer):
這是“get_valid_locations”function:
def get_valid_locations(board):
valid_locations = []
for col in range(BOARD_COLS):
if available_square(board, col):
valid_locations.append(col)
return valid_locations
這是“available_square”function:
def available_square(row, col):
return board[row][col] == 0
我剛剛注意到,您將available_square
與available_square(board, col)
board 和 col 稱為 arguments,您可能希望簽名為
def available_square(board, row, col):
....
並且調用為available_square(board, row, col)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.