def finalize_canonical_averages(<EOL>number_of_nodes, ps, canonical_averages, alpha,<EOL>):
spanning_cluster = (<EOL>(<EOL>'<STR_LIT>' in<EOL>canonical_averages.dtype.names<EOL>) and<EOL>'<STR_LIT>' in canonical_averages.dtype.names<EOL>)<EOL>ret = np.empty_like(<EOL>canonical_averages,<EOL>dtype=finalized_canonical_averages_dtype(<EOL>spanning_cluster=spanning_cluster<EOL>),<EOL>)<EOL>n = canonical_averages['<STR_LIT>']<EOL>sqrt_n = np.sqrt(canonical_averages['<STR_LIT>'])<EOL>ret['<STR_LIT>'] = n<EOL>ret['<STR_LIT:p>'] = ps<EOL>ret['<STR_LIT>'] = alpha<EOL>def _transform(<EOL>original_key, final_key=None, normalize=False, transpose=False,<EOL>):<EOL><INDENT>if final_key is None:<EOL><INDENT>final_key = original_key<EOL><DEDENT>keys_mean = [<EOL>'<STR_LIT>'.format(key)<EOL>for key in [original_key, final_key]<EOL>]<EOL>keys_std = [<EOL>'<STR_LIT>'.format(original_key),<EOL>'<STR_LIT>'.format(final_key),<EOL>]<EOL>key_ci = '<STR_LIT>'.format(final_key)<EOL>ret[keys_mean[<NUM_LIT:1>]] = canonical_averages[keys_mean[<NUM_LIT:0>]]<EOL>if normalize:<EOL><INDENT>ret[keys_mean[<NUM_LIT:1>]] /= number_of_nodes<EOL><DEDENT>array = canonical_averages[keys_std[<NUM_LIT:0>]]<EOL>result = np.sqrt(<EOL>(array.T if transpose else array) / (n - <NUM_LIT:1>)<EOL>)<EOL>ret[keys_std[<NUM_LIT:1>]] = (<EOL>result.T if transpose else result<EOL>)<EOL>if normalize:<EOL><INDENT>ret[keys_std[<NUM_LIT:1>]] /= number_of_nodes<EOL><DEDENT>array = ret[keys_std[<NUM_LIT:1>]]<EOL>scale = (array.T if transpose else array) / sqrt_n<EOL>array = ret[keys_mean[<NUM_LIT:1>]]<EOL>mean = (array.T if transpose else array)<EOL>result = scipy.stats.t.interval(<EOL><NUM_LIT:1> - alpha,<EOL>df=n - <NUM_LIT:1>,<EOL>loc=mean,<EOL>scale=scale,<EOL>)<EOL>(<EOL>ret[key_ci][..., <NUM_LIT:0>], ret[key_ci][..., <NUM_LIT:1>]<EOL>) = ([my_array.T for my_array in result] if transpose else result)<EOL><DEDENT>if spanning_cluster:<EOL><INDENT>_transform('<STR_LIT>')<EOL><DEDENT>_transform('<STR_LIT>', '<STR_LIT>', normalize=True)<EOL>_transform('<STR_LIT>', normalize=True, transpose=True)<EOL>return ret<EOL>
Finalize canonical averages