NumpyTensorSpace.__contains__¶
-
NumpyTensorSpace.
__contains__
(self, other)¶ Return
other in self
.- Returns
- containsbool
True
ifother
has aspace
attribute that is equal to this space,False
otherwise.
Examples
Elements created with the
TensorSpace.element
method are guaranteed to be contained in the same space:>>> spc = odl.tensor_space((2, 3), dtype='uint64') >>> spc.element() in spc True >>> x = spc.element([[0, 1, 2], ... [3, 4, 5]]) >>> x in spc True
Sizes, data types and other essential properties characterize spaces and decide about membership:
>>> smaller_spc = odl.tensor_space((2, 2), dtype='uint64') >>> y = smaller_spc.element([[0, 1], ... [2, 3]]) >>> y in spc False >>> x in smaller_spc False >>> other_dtype_spc = odl.tensor_space((2, 3), dtype='uint32') >>> z = other_dtype_spc.element([[0, 1, 2], ... [3, 4, 5]]) >>> z in spc False >>> x in other_dtype_spc False
On the other hand, spaces are not unique:
>>> spc2 = odl.tensor_space((2, 3), dtype='uint64') >>> spc2 == spc True >>> x2 = spc2.element([[5, 4, 3], ... [2, 1, 0]]) >>> x2 in spc True >>> x in spc2 True
Of course, random garbage is not in the space:
>>> spc = odl.tensor_space((2, 3), dtype='uint64') >>> None in spc False >>> object in spc False >>> False in spc False