Skip to content

Commit

Permalink
fix: unexpected 2dim mean and var when using 1dim data
Browse files Browse the repository at this point in the history
  • Loading branch information
Cloudac7 committed Apr 11, 2024
1 parent 42ee9cb commit 4f738ae
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion catflow/utils/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
from numpy.typing import ArrayLike


def block_average(data: ArrayLike, block_size: int, axis: int = 0) -> Tuple[float, float]:
def block_average(data: ArrayLike, block_size: int, axis: int = 0):
reshape_flag = False
data = np.array(data)
if data.ndim == 1:
reshape_flag = True
data = np.reshape(data, (-1, 1)) # Reshape data into a 2D array
N_b = data.shape[axis] // block_size
if N_b == 0:
Expand All @@ -21,6 +23,9 @@ def block_average(data: ArrayLike, block_size: int, axis: int = 0) -> Tuple[floa
blocked_data = np.mean(reshaped_data, axis=axis+1)
mean = np.mean(blocked_data, axis=axis)
var = np.std(blocked_data, ddof=1, axis=axis) / np.sqrt(N_b)
if reshape_flag:
mean = mean[0]
var = var[0]
return mean, var


Expand Down

0 comments on commit 4f738ae

Please sign in to comment.