diff --git a/python/paddle/fluid/variable_index.py b/python/paddle/fluid/variable_index.py index 83a569aacc911..7d1bbf8162c2e 100644 --- a/python/paddle/fluid/variable_index.py +++ b/python/paddle/fluid/variable_index.py @@ -306,8 +306,9 @@ def idx_empty(var): return paddle.empty(var_shape, dtype=var.dtype) from .layers.control_flow import cond - return cond(item.any(), lambda: idx_not_empty(var, item), - lambda: idx_empty(var)) + return cond( + paddle.logical_not(item.any()), lambda: idx_empty(var), + lambda: idx_not_empty(var, item)) def _getitem_impl_(var, item):