From multivariate asset returns $X$, we can calculate the sample covariance matrix $\Sigma$.
The definition of (any) portfolio variance is $w^\top \Sigma w$, where $w$ are portfolio weights.
If $X w$ is the portfolio-weighted asset returns series (a vector), shouldn't the variance of this vector of portfolio returns be equal to the variance of the portfolio, $w^\top \Sigma w$?
When I calculate both of them for the same dataset and weights, why don't they equal? $$Var(X w) \neq w^\top \Sigma w$$
import numpy as np
from numpy.random import randn
X = randn(1000,3) #3 assets with 1000 return observations
Sigma = np.cov(X.T) #covariance matrix
w = np.array([0.2,0.3,0.5]) #portfolio weights for 3 assets
print(np.var(X@w)) #this should equal the next line but doesn't
print(w@Sigma@w)