Average calculation of last elements in a sequence

28 Views Asked by At

Assuming I need to sample the average of the last $n$ elements in a sequence each time a new element is added to the sequence. Is there a way to get the new average without saving all the $n$ elements?