is the computed Hoteling's T square correct? I am testing the Hoteling Tsquare test on a toy example using scikit learn.
I am following the description in this this link.
Is the size of the obtained Tsquare values correct? Shouldn't it be a simple vector of size 13?
import numpy as np
from sklearn.decomposition import PCA
from sklearn import preprocessing

hald_text = """Y       X1      X2      X3      X4
    78.5    7       26      6       60
    74.3    1       29      15      52
    104.3   11      56      8       20
    87.6    11      31      8       47
    95.9    7       52      6       33
    109.2   11      55      9       22
    102.7   3       71      17      6
    72.5    1       31      22      44
    93.1    2       54      18      22
    115.9   21      47      4       26
    83.8    1       40      23      34
    113.3   11      66      9       12
    109.4   10      68      8       12
    """
    hald = np.loadtxt(hald_text.splitlines(), skiprows=1)


pca_sklearn=PCA(n_components=4)
data=hald

data=preprocessing.scale(data)

output=pca_sklearn.fit_transform(data)
output=pca_sklearn.transform(data.reshape(-1,1))

hoteling_metric=data.dot(pca_sklearn.components_.T).dot(np.diag(1/pca_sklearn.explained_variance_)).dot(pca_sklearn.components_).dot(data.T)
print(hoteling_metric)

 A: Mathematically, your conclusion is correct that the diagonals of your result equal the Hotelling's $T^2$ values for each sample. However, it took me a while to figure that out. So I'm posting my own answer in case it helps anyone else who is trying to calculate Hotelling's $T^2$ values using Python.
According to the page you linked from wiki.eigenvector.com, "Hotelling's $T^2$ values represent a measure of the variation of each sample within the model".  The formula given on that page (copied below) is for calculating the $T^2$ value for one sample:
$$ T_i^2 = t_i\lambda^{-1}t_i^T = x_iP_k\lambda^{-1}P_k^Tx_i^T $$ 
To get $T^2$ values for all 13 samples in your data, you can use this formula on each sample.  Here's how it looks in Python, starting with your data:
data=preprocessing.scale(data)

output=pca_sklearn.fit_transform(data)

loadings_p = pca_sklearn.components_.T
eigenvalues = pca_sklearn.explained_variance_

hotelling_t2s = np.array([xi.dot(loadings_p)
                            .dot(np.diag(eigenvalues ** -1))
                            .dot(loadings_p.T)
                            .dot(xi.T)
                          for xi in data])

A: After a bit of reflexion, it seems that the Tsquare given by these lines of code lies simply in the diagonal of the matrix. The other values doesn't make sense.
