Q:

What is proper solution when dealing with 0 std for z-score computation?

I have some historical data (example purpose):
historical = np.array([95,96,94,93,92])

and also i have a current value:
current_value = 94

So i'm computing z-score for the current_value:
z_score = (current_value - np.mean(historical)) / np.std(historical)

if z_score is higher than 1 there will be a warning message.
And finally the historical will be updated with the current_value
historical = np.append(historical, [current_value])

So, there will be a case when i will have just one value in historical, 
that means the std will be equal to 0 =>  z_score = inf.
Here comes my question: What is the proper approach when std = 0?
I was thinking of replacing the 0 std with 1.
Is that a viable solution or should I use another approach?

A:

This is the way I've typically approached this problem.

Use exponential smoothing to determine the np.mean. This means more recent observations are given more weight. This also means that you don't have to keep that long vector of historical around.
Similarly, use exponential smoothing on the standard deviation. This means that as your number of observations grows, the precise starting value for the standard deviation does not matter.
The alphas for these exponential smoothings may be higher at the start than after you have a lot of observations.
In terms of what to use for that initial value (yes, I'm finally getting around to your question), ask yourself if the first observation is x, say 666, how much of a difference from 666 do you want to flag when that second observation comes in? That will let you back into the initial value. Given the small amount of data you have at that point, the initial value should be pretty high.

Personally, flagging a |z| of 1 or more is too tight for a real world application. You're going to be reviewing a lot of false alarms.  But I don't know what your application is, so maybe that's what you want.

