Answer the question
In order to leave comments, you need to log in
How to compare two arrays?
It is necessary to compare two arrays, taking into account the order and taking into account that if an element in the first array = -1, then in the second it can be anything.
table = [
[1, 0, -1],
[-1, 0, 0],
[-1, 0, 0]
]
tb =
if all(t in tb for t in table):
...
Answer the question
In order to leave comments, you need to log in
Well...
table = [
[1, 0, -1],
[-1, 0, 0],
[-1, 0, 0]
]
tb =
n = [[i for k,i in enumerate(x) if k not in d] in [[i for k,i in enumerate(l) if k not in d] for l in tb] for x, d in zip(table, [[k for k,i in enumerate(x) if i==-1] for x in table])]
print(n)
from itertools import compress
def equal_but_one(data, storage, skip_value=-1):
mask = [number != skip_value for number in data]
data_compressed = list(compress(data, mask))
return data_compressed in (list(compress(item, mask)) for item in storage)
all(equal_but_one(data, tb) for data in table)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question