From 9c7d31e5d6120479b6aca2a5d074538cdd160b80 Mon Sep 17 00:00:00 2001 From: youkaichao Date: Wed, 8 Jul 2020 08:10:34 +0800 Subject: [PATCH] bugfix for empty_ (#114) * bugfix for empty_ * use v.__class__(0) for scalar --- tianshou/data/batch.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tianshou/data/batch.py b/tianshou/data/batch.py index 1a0ef43..2a670ab 100644 --- a/tianshou/data/batch.py +++ b/tianshou/data/batch.py @@ -569,10 +569,8 @@ class Batch: else: # scalar value warnings.warn('You are calling Batch.empty on a NumPy scalar, ' 'which may cause undefined behaviors.') - if isinstance(v, (np.generic, Number)): - self.__dict__[k] *= 0 - if np.isnan(self.__dict__[k]): - self.__dict__[k] = 0 + if isinstance(v, (np.number, np.bool_, Number)): + self.__dict__[k] = v.__class__(0) else: self.__dict__[k] = None return self