@@ -519,34 +519,34 @@ def _values_by_copy(self, flow=False) -> np.typing.NDArray[Any]: # noqa: F821
519519 return np .array ([self .GetBinContent (* bin ) for bin in bin_combinations ]).reshape (_shape (self , flow = flow ))
520520
521521
522- def _variances (self ) -> np .typing .NDArray [Any ]: # noqa: F821
522+ def _variances (self , flow = False ) -> np .typing .NDArray [Any ]: # noqa: F821
523523 import numpy as np
524524
525- sum_of_weights = self .values ()
525+ sum_of_weights = self .values (flow = flow )
526526
527527 if not _hasWeights (self ) and _kind (self ) == Kind .COUNT :
528528 return sum_of_weights
529529
530- sum_of_weights_squared = _get_sum_of_weights_squared (self )
530+ sum_of_weights_squared = _get_sum_of_weights_squared (self , flow = flow )
531531
532532 if _kind (self ) == Kind .MEAN :
533- counts = self .counts ()
533+ counts = self .counts (flow = flow )
534534 variances = sum_of_weights_squared .copy ()
535535 variances [counts <= 1 ] = np .nan
536536 return variances
537537
538538 return sum_of_weights_squared
539539
540540
541- def _counts (self ) -> np .typing .NDArray [Any ]: # noqa: F821
541+ def _counts (self , flow = False ) -> np .typing .NDArray [Any ]: # noqa: F821
542542 import numpy as np
543543
544- sum_of_weights = self .values ()
544+ sum_of_weights = self .values (flow = flow )
545545
546546 if not _hasWeights (self ):
547547 return sum_of_weights
548548
549- sum_of_weights_squared = _get_sum_of_weights_squared (self )
549+ sum_of_weights_squared = _get_sum_of_weights_squared (self , flow = flow )
550550
551551 return np .divide (
552552 sum_of_weights ** 2 ,
@@ -556,16 +556,23 @@ def _counts(self) -> np.typing.NDArray[Any]: # noqa: F821
556556 )
557557
558558
559- def _get_sum_of_weights_squared (self ) -> np .typing .NDArray [Any ]: # noqa: F821
559+ def _get_sum_of_weights_squared (self , flow = False ) -> np .typing .NDArray [Any ]: # noqa: F821
560560 import numpy as np
561561
562- shape = _shape (self , flow = False )
563562 sumw2_arr = np .frombuffer (
564563 self .GetSumw2 ().GetArray (),
565564 dtype = self .GetSumw2 ().GetArray ().typecode ,
566565 count = self .GetSumw2 ().GetSize (),
567566 )
568- return sumw2_arr [tuple ([slice (1 , - 1 )] * len (shape ))].reshape (shape , order = "F" ) if sumw2_arr .size > 0 else sumw2_arr
567+
568+ reshaped = sumw2_arr .reshape (_shape (self , flow = True ), order = "F" )
569+
570+ if flow :
571+ slices = tuple (slice (None ) for _ in range (self .GetDimension ()))
572+ else :
573+ slices = tuple (slice (1 , - 1 ) for _ in range (self .GetDimension ()))
574+
575+ return reshaped [slices ]
569576
570577
571578values_func_dict : dict [str , Callable ] = {
0 commit comments