python怎么用numpy_如何使用numpy.all()或numpy.any()?

我试图在2D numpy数组中搜索特定值,get_above方法返回字符“initial char”上方的坐标列表def get_above(current, wordsearch):

list_of_current_coords = get_coords_current(current, wordsearch)

#print(list_of_current_coords)

length = len(list_of_current_coords)

first_coords = []

second_coords = []

for x in range(length):

second = list_of_current_coords[x][1]

new_first = list_of_current_coords[x][0] - 1

first_coords.append(new_first)

second_coords.append(second)

combined = [first_coords, second_coords]

above_coords = []

for y in range(length):

lst2 = [item[y] for item in combined]

above_coords.append(lst2)

return above_coords

def search_above(initial_char, target, matrix):

above_coords = get_above(initial_char, matrix)

length = len(above_coords)

for x in range(length):

if matrix[above_coords[x]] == target:

print(above_coords[x])

else:

print('not found')

调用函数时出现此错误:

ValueError:具有多个元素的数组的真值不明确。使用a.any()或a.all()

任何帮助都将不胜感激!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值