我正在为我的numpy逻辑语句编写if语句。但是,似乎我尝试了所有事情,总是得到
“ ValueError:具有多个元素的数组的真值不明确。请使用a.any()或a.all()
很抱歉,如果这是一个愚蠢的问题。
import numpy as np
w = 8
l = 5
s = 2
blocked = []
file_blocked = [17,20]
board = np.arange(w*l)
board = board.reshape(l,w)
start = board[s,0]
currentpoint = start
print(board)
print()
for j in range(len(file_blocked)):
each_block = file_blocked[j]
each_block = np.argwhere(board == each_block)
each_block = np.hstack(each_block)
blocked.append(each_block)
place_a = np.logical_and(np.argwhere(board == currentpoint) + [0,1] != blocked, np.argwhere(board == currentpoint) + [0,2] != blocked, np.argwhere(board == currentpoint) + [0,3] != blocked)