compute analysis error covariance matrix
P = (1/(N-1)) * (xai) @ (xai).T
return uai, P
```
#### *8.2. Example: Lorenz 63 System*

The same Lorenz 63 system is used to showcase the performance of both the EnKF and DEnKF. In Listing 19, we show the Python application of the EnKF algorithm. In general, the size of ensemble *N* is much smaller than the state dimension *n* for the implementation of EnKF to be computationally feasible. However, the state dimension in the Lorenz 63 is 3, and an ensemble of size 3 or less is trivial. The uncertainty in the covariance approximation via the Monte Carlo framework with such small ensemble becomes very high and resulting predictions are unreliable. There exists various approaches that help to increase the fidelity of small ensembles, including localization and inflation. In Section 9.2, we describe simple application of inflation factor and its impact with small ensembles. Here, we stick with the basic implementation with an ensemble size of 10 for both EnKF and DEnKF.

✝ ✆

**Listing 19.** Implementation of EnKF for the Lorenz 63 system. ✞ ☎

```
#%% Application: Lorenz 63
########################### Data Assimilation #################################
u0b = np.array([2.0,3.0,4.0])
sig_b= 0.1
B = sig_b**2*np.eye(3)
Q = 0.0*np.eye(3)
#time integration
ub = np.zeros([3,nt+1])
ub[:,0] = u0b
ua = np.zeros([3,nt+1])
ua[:,0] = u0b
n=3 #state dimension
m=3 #measurement dimension