I don't know if this is a safe assumption, but if `a` is a non-jagged matrix, then:

```python
n_rows, n_cols = a.shape
group_means = a.mean(axis=1)
group_variances = a.var(ddof=1, axis=1) * (n_cols - 1)
num_cases = n_rows * n_cols
all_vals = a.reshape(n_rows * n_cols)
```

However, if it can come in jagged, then the above of course wouldn't work.