From 4f470b35308d93b44215c6adc22636e1176de6fd Mon Sep 17 00:00:00 2001 From: Bas van Beek Date: Thu, 9 Sep 2021 11:02:07 +0200 Subject: BUG: Fixed an issue wherein `var` would raise for 0d object arrays --- numpy/core/_methods.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'numpy/core/_methods.py') diff --git a/numpy/core/_methods.py b/numpy/core/_methods.py index e475b94df..a239e2c87 100644 --- a/numpy/core/_methods.py +++ b/numpy/core/_methods.py @@ -221,8 +221,10 @@ def _var(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False, *, if isinstance(arrmean, mu.ndarray): arrmean = um.true_divide(arrmean, div, out=arrmean, casting='unsafe', subok=False) - else: + elif hasattr(arrmean, "dtype"): arrmean = arrmean.dtype.type(arrmean / rcount) + else: + arrmean = arrmean / rcount # Compute sum of squared deviations from mean # Note that x may not be inexact and that we need it to be an array, -- cgit v1.2.1