diff --git a/tensordict/tensordict.py b/tensordict/tensordict.py index 0cde92342..e143c07d4 100644 --- a/tensordict/tensordict.py +++ b/tensordict/tensordict.py @@ -7924,6 +7924,8 @@ def sort_keys(element): rename_key = _renamed_inplace_method(rename_key_) def where(self, condition, other, *, out=None, pad=None): + if condition.ndim < self.ndim: + condition = expand_right(condition, self.batch_size) condition = condition.unbind(self.stack_dim) if _is_tensor_collection(other.__class__) or ( isinstance(other, Tensor)