Suppose I have a list that contains a bunch of numpy ndarrays (or even torch Tensors):
a, b, c = np.random.rand(3, 3), np.random.rand(3, 3), np.random.rand(3, 3)
collection = [a, b, c]
Now if I was to check whether array b was in collection (assuming I don't know what arrays exist in collection), then attempting: b in collection spits out the following error:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
And the same would apply to tuples containing arrays.
One way around this was to do a list comprehension:
True in [(b == x).all() for x in collection]
However this requires a for loop and I was wondering if there was a more "efficient" way to accomplish this?