Variance of a portfolio In this blog post the author mentions the following:
[... Given several arrays holding returns for a portfolio], one should calculate the standard deviation via the following function call:
(1) $\sigma= \sqrt{w^{T}Cw}$, where $C$ is the covariance matrix of the returns $R = p^Tw$ as measured by numpy
This is in contrast to this other formula which should not be used:
(2) $\sigma = \text{std}\left(R^T.w\right)$
my question is why?

I think the same question can be rephrased as follows:
$\sigma^2$ should be calculated as:
(3) $\sigma^2 = \sum_i w_i^2 \sigma_{i}^2 + \sum_i \sum_{j \neq i} w_i w_j \sigma_i \sigma_j \rho_{ij}$ where $\rho_{ij}$ is the Pearson product-moment correlation  between the returns on assets ''i'' and ''j''
and not as:
(4) $\sigma^2 = \sum_i w_i^2 \sigma_{i}^2 $
again, why?

Trying to derive the formula
Property 3 here reads:
$ \operatorname{cov}(\mathbf{A X} + \mathbf{a}) = \mathbf{A}\, \operatorname{cov}(\mathbf{X})\, \mathbf{A^{\rm T}} $
Now, let's consider $\mathbf{A} = w$ and $\mathbf{X}=p$. Both are $(N,1)$ matrices, with $N$ being the number of assets in the portfolio. If I do the math above I end up with multiplying matrices of the following dimensions:
$(N,1) \;x \;(N,N) \;x \;(1,N)$
which results in a new matrix $(N,N)$. If I then do the square root of this matrix result I don't end up with a scalar quantity as I presume one does in in Eqs. (1) an (3). What am I missing?
 A: This is a compilation of comments resulting in the OP's understanding.
Property 3 of the covariance matrix shows how to calculate the covariance of a {matrix (or vector)} times {a vector having known covariance}:
$ \operatorname{cov}(\mathbf{A X} + \mathbf{a}) = \mathbf{A}\, \operatorname{cov}(\mathbf{X})\, \mathbf{A^{\rm T}} $.  
Since $R = p^Tw$, we can replace $A=w^T$ and $X=p$ above, ending up with:
$\text{cov}(R) = w^T  \text{cov}\left(p\right)  w$
and since $cov(p) = C$, we have:
$\text{cov}(R) = w^T  C  w$
Now, if R is N x 1, then $C$ is N x N, and $w$ is N x 1, we end up with the following dimensions for $cov(R)$:
1 x N times N x N times N x 1 =  1 x 1.  
This 1 x 1 covariance matrix is also known as the variance.  Taking the square root provides the standard deviation.
Note that equation (2) in the posted question does not account for non-zero correlation (covariance) among the components of p, and so is not valid unless all  correlations across components are zero, in which case the covariance "property 3" calculation reduces to equation (2) as a special case.
