@@ -385,39 +385,38 @@ def _from_storage(self, stripped_indexer, drop_axes, out_shape, out_dtype,
385
385
if method is not None :
386
386
# Apply the method (again) to aggregate the result
387
387
out = method (out )
388
-
388
+ shape1 = (1 ,) * len (out_shape )
389
+
389
390
if self ._components :
390
391
# Return a dictionary of components containing the
391
392
# reduced data and the sample size ('n'). (Rationale:
392
393
# cf-python needs the sample size for all reductions;
393
394
# see the 'mtol' parameter of cf.Field.collapse.)
394
395
#
395
- # Note that in this case the reduced data must always
396
- # have the same number of dimensions as the original
397
- # array, i.e. 'drop_axes' is always considered False,
396
+ # Note that in all components must always have the
397
+ # same number of dimensions as the original array,
398
+ # i.e. 'drop_axes' is always considered False,
398
399
# regardless of its setting. (Rationale: dask
399
400
# reductions require the per-dask-chunk partial
400
401
# reductions to retain these dimensions so that
401
402
# partial results can be concatenated correctly.)
402
- n = np .prod (out_shape )
403
- shape1 = (1 ,) * len (out_shape )
404
- n = np .reshape (n , shape1 )
405
403
out = out .reshape (shape1 )
406
404
405
+ n = np .sum (counts ).reshape (shape1 )
407
406
if self ._method == "mean" :
408
407
# For the average, the returned component is
409
408
# "sum", not "mean"
410
- out = {"sum" : out , "n" : sum ( counts ) }
409
+ out = {"sum" : out , "n" : n }
411
410
else :
412
- out = {self ._method : out , "n" : sum ( counts ) }
411
+ out = {self ._method : out , "n" : n }
413
412
else :
414
413
# Return the reduced data as a numpy array. For most
415
414
# methods the data is already in this form.
416
415
if self ._method == "mean" :
417
416
# For the average, it is actually the sum that has
418
417
# been created, so we need to divide by the sample
419
418
# size.
420
- out = out / sum (counts )
419
+ out = out / np . sum (counts ). reshape ( shape1 )
421
420
422
421
return out
423
422
0 commit comments