@staticmethod<EOL><INDENT>def coarse_grain(G, ncg):<DEDENT>
if ncg <= <NUM_LIT:1>:<EOL><INDENT>return G<EOL><DEDENT>G = numpy.asarray(G)<EOL>nbin, remainder = divmod(G.shape[-<NUM_LIT:1>], ncg)<EOL>if remainder != <NUM_LIT:0>:<EOL><INDENT>nbin += <NUM_LIT:1><EOL><DEDENT>return numpy.transpose([<EOL>numpy.sum(G[..., i:i+ncg], axis=-<NUM_LIT:1>) / G[..., i:i+ncg].shape[-<NUM_LIT:1>]<EOL>for i in numpy.arange(<NUM_LIT:0>, ncg * nbin, ncg)<EOL>])<EOL>
Coarse-grain last index of array ``G``.

        Bin the last index of array ``G`` in bins of width ``ncg``, and
        replace each bin by its average. Return the binned results.

        Args:
            G: Array to be coarse-grained.
            ncg: Bin width for coarse-graining.