public static function covarianceMatrix(array $data, ?array $means = null): array
    {
        $n = count($data[0]);

        if ($means === null) {
            $means = [];
            for ($i = 0; $i < $n; ++$i) {
                $means[] = Mean::arithmetic(array_column($data, $i));
            }
        }

        $cov = [];
        for ($i = 0; $i < $n; ++$i) {
            for ($k = 0; $k < $n; ++$k) {
                if ($i > $k) {
                    $cov[$i][$k] = $cov[$k][$i];
                } else {
                    $cov[$i][$k] = self::fromDataset(
                        $data,
                        $i,
                        $k,
                        true,
                        $means[$i],
                        $means[$k]
                    );
                }
            }
        }

        return $cov;
    }
public static function covarianceMatrix(array $data, ?array $means = null): array
    {
        $n = count($data[0]);

        if ($means === null) {
            $means = [];
            for ($i = 0; $i < $n; ++$i) {
                $means[] = Mean::arithmetic(array_column($data, $i));
            }
        }

        $cov = [];
        for ($i = 0; $i < $n; ++$i) {
            for ($k = 0; $k < $n; ++$k) {
                if ($i > $k) {
                    $cov[$i][$k] = $cov[$k][$i];
                } else {
                    $cov[$i][$k] = self::fromDataset(
                        $data,
                        $i,
                        $k,
                        true,
                        $means[$i],
                        $means[$k]
                    );
                }
            }
        }

        return $cov;
    }
public static function covarianceMatrix ( array $ data , ? array $ means = null ) : array { $ n = count ( $ data [ 0 ] ) ; if ( $ means === null ) { $ means = [ ] ; for ( $ i = 0 ; $ i < $ n ; ++ $ i ) { $ means [ ] = Mean :: arithmetic ( array_column ( $ data , $ i ) ) ; } } $ cov = [ ] ; for ( $ i = 0 ; $ i < $ n ; ++ $ i ) { for ( $ k = 0 ; $ k < $ n ; ++ $ k ) { if ( $ i > $ k ) { $ cov [ $ i ] [ $ k ] = $ cov [ $ k ] [ $ i ] ; } else { $ cov [ $ i ] [ $ k ] = self :: fromDataset ( $ data , $ i , $ k , true , $ means [ $ i ] , $ means [ $ k ] ) ; } } } return $ cov ; }
Returns the covariance matrix of n-dimensional data

@param array|null $means
Returns the covariance matrix of n - dimensional data