[英]How can I check if an 1-D array is in a 2-D array?
我在 numpy [[1 0 0 1 1 1], [1 0 0 0 1 0], [1 1 0 0 1 0], [0 1 0 1 1 1], [0 0 0 1 0 1]]
中有以下矩陣[[1 0 0 1 1 1], [1 0 0 0 1 0], [1 1 0 0 1 0], [0 1 0 1 1 1], [0 0 0 1 0 1]]
我想檢查數組[1 0 0 0 1 0]
是否在矩陣中。 我嘗試使用
if 1-array in 2-D array:
print('True')
但我有一個錯誤DeprecationWarning: elementwise comparison failed; this will raise an error in the future.
DeprecationWarning: elementwise comparison failed; this will raise an error in the future.
如果我跑
import numpy as np
arr_2d = np.array([[1, 0, 0, 1, 1, 1],
[1, 0, 0, 0, 1, 0],
[1, 1, 0, 0, 1, 0],
[0, 1, 0, 1, 1, 1],
[0, 0, 0, 1, 0, 1]])
arr_1d = np.array([1, 0, 0, 0, 1, 0])
print(arr_1d in arr_2d)
它在沒有警告的情況下返回 True。
我建議發布你用來獲取那些 arrays 的代碼,這樣我們就可以看看它們是否有問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.