def hist_last_nonzero(hist, return_index=False, copy=True):
<EOL>hist_t = np.array(hist)<EOL>index = (np.where(hist_t)[-<NUM_LIT:1>][-<NUM_LIT:1>] + <NUM_LIT:1>) if np.sum(hist_t) > <NUM_LIT:1> else hist_t.shape[<NUM_LIT:0>]<EOL>masked_hist = np.ma.array(hist, copy=copy, mask=True)<EOL>masked_hist.mask[index:] = False<EOL>if return_index:<EOL><INDENT>return masked_hist, index<EOL><DEDENT>else:<EOL><INDENT>return masked_hist<EOL><DEDENT>
Find the last nonzero index and mask the remaining entries.

    Parameters
    ----------
    hist : array_like, iterable
        Input histogram with dimension at most 1.
    return_index : bool, optional
        If true, return the index.
    copy : bool, optional
        Whether to copy the input data (True), or to use a reference instead. Default is False.

    Returns
    -------
    masked_hist : masked_array
       Hist with masked elements.
    masked_hist : masked_array, tuple
        Hist with masked elements and index of the element after the last nonzero value.