Takes a data and returns a lower dimensional version
of this data while preserving $totalVariance or $numFeatures. <br>
$data is an n-by-m matrix and returned array is
n-by-k matrix where k <= m
506566
public function fit(array $data): array
    {
        $numRows = count($data);
        $this->data = $data;

        if ($this->gamma === null) {
            $this->gamma = 1.0 / $numRows;
        }

        $matrix = $this->calculateKernelMatrix($this->data, $numRows);
        $matrix = $this->centerMatrix($matrix, $numRows);

        $this->eigenDecomposition($matrix);

        $this->fit = true;

        return Matrix::transposeArray($this->eigVectors);
    }
844439
def make_data(n,m):
    """"""
    I = range(1,n+1)
    J = range(1,m+1)
    x,y,w = {},{},{}
    for i in I:
        x[i] = random.randint(0,100)
        y[i] = random.randint(0,100)
        w[i] = random.randint(1,5)
    return I,J,x,y,w
354354
private double[][] createMatrix() {
        double time = 0;
        double tmin = 0;
        tmin = rainData[0][0];
        time = tmin;
        double[][] matrix = new double[nTime][networkPipes.length + 1];

        for( int i = 0; i < nTime; ++i ) {
            matrix[i][0] = time;
            time += dt;
        }
        return matrix;
    }
170401
def asarray2d(a):
    """"""
    arr = np.asarray(a)
    if arr.ndim == 1:
        arr = arr.reshape(-1, 1)
    return arr
909027
public function lu() : array
    {
        if (!$this->isSquare()) {
            throw new RuntimeException('Cannot decompose a non'
                . ' square matrix.');
        }

        $l = self::identity($this->n)->asArray();
        $u = self::zeros($this->n, $this->n)->asArray();
        $p = self::identity($this->n)->asArray();

        for ($i = 0; $i < $this->n; $i++) {
            $max = $this->a[$i][$i];

            $row = $i;

            for ($j = $i; $j < $this->n; $j++) {
                if ($this->a[$j][$i] > $max) {
                    $max = $this->a[$j][$i];
                    
                    $row = $j;
                }
            }
            
            if ($i !== $row) {
                $temp = $p[$i];

                $p[$i] = $p[$row];
                $p[$row] = $temp;
            }
        }

        $p = self::quick($p);

        $pa = $p->matmul($this);

        for ($i = 0; $i < $this->n; $i++) {
            for ($j = 0; $j <= $i; $j++) {
                $sigma = 0;

                for ($k = 0; $k < $j; $k++) {
                    $sigma += $u[$k][$i] * $l[$j][$k];
                }

                $u[$j][$i] = $pa[$j][$i] - $sigma;
            }

            for ($j = $i; $j < $this->n; $j++) {
                $sigma = 0;

                for ($k = 0; $k < $i; $k++) {
                    $sigma += $u[$k][$i] * $l[$j][$k];
                }

                $l[$j][$i] = ($pa[$j][$i] - $sigma)
                    / ($u[$i][$i] ?: self::EPSILON);
            }
        }

        $l = self::quick($l);
        $u = self::quick($u);

        return [$l, $u, $p];
    }
227885
public static double[][] cor(double[][] data, double[] mu) {
        double[][] sigma = cov(data, mu);

        int n = data[0].length;
        double[] sd = new double[n];
        for (int i = 0; i < n; i++) {
            sd[i] = sqrt(sigma[i][i]);
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j <= i; j++) {
                sigma[i][j] /= sd[i] * sd[j];
                sigma[j][i] = sigma[i][j];
            }
        }

        return sigma;
    }
835234
public function variance()
    {
        if ($this->n === 0) {
            throw new RuntimeException('Variance is not defined for vectors'
            . ' with less than 1 element.');
        }

        $ssd = $this->subtract($this->mean())
            ->square()
            ->sum();

        return $ssd / $this->n;
    }
198839
def array(self):
        
        if self.bands == 1:
            return self.matrix()
        else:
            arr = self.raster.ReadAsArray().transpose(1, 2, 0)
            if isinstance(self.nodata, list):
                for i in range(0, self.bands):
                    arr[:, :, i][arr[:, :, i] == self.nodata[i]] = np.nan
            else:
                arr[arr == self.nodata] = np.nan
            return arr
1133818
protected function normalize(array $data, int $n): array
    {
        if (count($this->means) === 0) {
            $this->calculateMeans($data, $n);
        }

        // Normalize data
        foreach (array_keys($data) as $i) {
            for ($k = 0; $k < $n; ++$k) {
                $data[$i][$k] -= $this->means[$k];
            }
        }

        return $data;
    }
631554
public static double[][] cov(double[][] data, double[] mu) {
        double[][] sigma = new double[data[0].length][data[0].length];
        for (int i = 0; i < data.length; i++) {
            for (int j = 0; j < mu.length; j++) {
                for (int k = 0; k <= j; k++) {
                    sigma[j][k] += (data[i][j] - mu[j]) * (data[i][k] - mu[k]);
                }
            }
        }

        int n = data.length - 1;
        for (int j = 0; j < mu.length; j++) {
            for (int k = 0; k <= j; k++) {
                sigma[j][k] /= n;
                sigma[k][j] = sigma[j][k];
            }
        }

        return sigma;
    }
421721
public function gaussianElimination() : array
    {
        $minDim = min($this->shape());

        $b = $this->a;

        $swaps = 0;

        for ($k = 0; $k < $minDim; $k++) {
            $index = $k;

            for ($i = $k; $i < $this->m; $i++) {
                if (abs($b[$i][$k]) > abs($b[$index][$k])) {
                    $index = $i;
                }
            }

            if ($b[$index][$k] == 0) {
                throw new RuntimeException('Cannot compute row echelon form'
                    . ' of a singular matrix.');
            }

            if ($k !== $index) {
                $temp = $b[$k];

                $b[$k] = $b[$index];
                $b[$index] = $temp;

                $swaps++;
            }

            $diag = $b[$k][$k];

            for ($i = $k + 1; $i < $this->m; $i++) {
                $scale = $diag != 0 ? $b[$i][$k] / $diag : 1;
                
                for ($j = $k + 1; $j < $this->n; $j++) {
                    $b[$i][$j] -= $scale * $b[$k][$j];
                }
                
                $b[$i][$k] = 0;
            }
        }

        $b = self::quick($b);

        return [$b, $swaps];
    }
1181076
public double[] getVariances() {
		double N = this.size();
    	double[] LS = new double[this.getNrOfDimensions()];
    	double[] SS = new double[this.getNrOfDimensions()];
		double[] tmpFeatures;
		double[] variances = new double[this.getNrOfDimensions()];

		for (DataObject dataObject : dataList) {
			tmpFeatures = dataObject.getFeatures();
			for (int j = 0; j < tmpFeatures.length; j++) {
				LS[j] += tmpFeatures[j];
				SS[j] += tmpFeatures[j] * tmpFeatures[j];
			}
		}
		
		// sigmaSquared[i] = (SS[i] / N) - ((LS[i] * LS [i]) / (N * N));
		for (int i = 0; i < LS.length; i++) {
			variances[i] = (SS[i] / N - ((LS[i] / N)*(LS[i] / N)));
		}
		
		return variances;
    }
605348
protected function normalize(array $data, int $n)
    {
        if (empty($this->means)) {
            $this->calculateMeans($data, $n);
        }

        // Normalize data
        foreach ($data as $i => $row) {
            for ($k = 0; $k < $n; ++$k) {
                $data[$i][$k] -= $this->means[$k];
            }
        }

        return $data;
    }
943220
def split_data(data, squeeze=False):
    
    vdata = np.atleast_2d(data)
    nr_freqs = int(vdata.shape[1] / 2)
    part1 = vdata[:, 0:nr_freqs]
    part2 = vdata[:, nr_freqs:]
    if(squeeze):
        part1 = part1.squeeze()
        part2 = part2.squeeze()
    return part1, part2
631340
def get_array_ndim(self, key):
        """"""
        data = self.model.get_data()
        return data[key].ndim
563717
public function to_array($data = null)
	{
		if ($data === null)
		{
			$data = $this->_data;
		}

		$array = array();

		if (is_object($data) and ! $data instanceof \Iterator)
		{
			$data = get_object_vars($data);
		}

		if (empty($data))
		{
			return array();
		}

		foreach ($data as $key => $value)
		{
			if (is_object($value) or is_array($value))
			{
				$array[$key] = $this->to_array($value);
			}
			else
			{
				$array[$key] = $value;
			}
		}

		return $array;
	}
629552
def array(self):
        
        return np.eye(self.M, self.N, self.k)