Given a stream of sensor data from a vehicle, design a sliding window algorithm to detect anomalies in real time.
Implement detect_anomalies(sensor_values, window_size, threshold). Evaluate each value only after window_size earlier values are available. Return the zero-based indices where the value differs from the preceding window mean by strictly more than threshold standard deviations. Use population standard deviation. If the window standard deviation is zero, mark the value anomalous only when it differs from the window value. Return an empty list when no complete preceding window exists.
def detect_anomalies(sensor_values, window_size, threshold):