Convert to the matrix.
975235
def to_matrix(self, n_qubits=-1):
        """"""
        if self.is_identity:
            if n_qubits == -1:
                return self.matrix
            else:
                return reduce(np.kron, [I.matrix for _ in range(n_qubits)])
        if n_qubits == -1:
            n_qubits = _n(self) + 1
        if _n(self) == 0:
            mat = self.matrix
        else:
            mat = reduce(np.kron, [I.matrix for _ in range(_n(self))])
            mat = np.kron(mat, self.matrix)
        if n_qubits > _n(self) + 1:
            mat = reduce(np.kron, [I.matrix for _ in range(n_qubits - _n(self) - 1)], mat)
        return mat
368438
def translate_matrix(m, v):
    """"""
    (a, b, c, d, e, f) = m
    (x, y) = v
    return (a, b, c, d, x*a+y*c+e, x*b+y*d+f)
141494
function(x) {
            
            if (x == null) return this.decompose(this.mtx).translateX;
            
            return new Matrix(this.mtx && this.mtx.translate(x,0));
        }
1053344
def am_to_im(am):
    
    """
    if am.shape[0] != am.shape[1]:
        raise Exception('Adjacency matrices must be square')
    if am.format != 'coo':
        am = am.tocoo(copy=False)
    conn = sp.vstack((am.row, am.col)).T
    row = conn[:, 0]
    data = am.data
    col = sp.arange(sp.size(am.data))
    if istriangular(am):
        row = sp.append(row, conn[:, 1])
        data = sp.append(data, data)
        col = sp.append(col, col)
    im = sprs.coo.coo_matrix((data, (row, col)), (row.max()+1, col.max()+1))
    return im
1013304
def im2mat(I):
    """"""
    return I.reshape((I.shape[0] * I.shape[1], I.shape[2]))
285459
def not0(a):
    """"""
    return matrix(list(map(lambda x: 1 if x == 0 else x, a)), a.size)
665922
public static void convert(DMatrix input , FMatrix output ) {
        if( input.getNumRows() != output.getNumRows() )
            throw new IllegalArgumentException("Number of rows do not match");
        if( input.getNumCols() != output.getNumCols() )
            throw new IllegalArgumentException("Number of columns do not match");

        for( int i = 0; i < input.getNumRows(); i++  ) {
            for( int j = 0; j < input.getNumCols(); j++ ) {
                output.unsafe_set(i,j, (float)input.unsafe_get(i,j));
            }
        }
    }
1223155
function(scale,originX,originY) {
            originX = originX || 0;
            originY = originY || 0;
            return new Matrix(this.mtx && this.mtx.translate(originX,originY).scale(scale).translate(-originX,-originY));
        }
1215386
function() {
      var determinant;
      determinant = this.a * this.d - this.b * this.c;
      return Matrix(this.d / determinant, -this.b / determinant, -this.c / determinant, this.a / determinant, (this.c * this.ty - this.d * this.tx) / determinant, (this.b * this.tx - this.a * this.ty) / determinant);
    }
623725
def matrix(self, _):
        """"""
        x, y, z = self.coord
        return np.array([
            [1., 0., 0., x],
            [0., 1., 0., y],
            [0., 0., 1., z],
            [0., 0., 0., 1.]
        ])
578026
private function getSamplesMatrix(): Matrix
    {
        $samples = [];
        foreach ($this->samples as $sample) {
            array_unshift($sample, 1);
            $samples[] = $sample;
        }

        return new Matrix($samples);
    }
1152201
public Matrix transpose()
    {
        double tv[][] = new double[nCols][nRows];  // transposed values

        // Set the values of the transpose.
        for (int r = 0; r < nRows; ++r) {
            for (int c = 0; c < nCols; ++c) {
                tv[c][r] = values[r][c];
            }
        }

        return new Matrix(tv);
    }
932251
def apply(self, matrix):
		
		view = matrix[ self.indices() ]
		return self.transform(view) if self.transform != None else view
1363549
def _convert_to_spmatrix(operators):
        """"""
        # Lazy import to improve `import odl` time
        import scipy.sparse

        # Convert ops to sparse representation. This is not trivial because
        # operators can be indexable themselves and give the wrong impression
        # of an extra dimension. So we have to infer the shape manually
        # first and extract the indices of nonzero positions.
        nrows = len(operators)
        ncols = None
        irow, icol, data = [], [], []
        for i, row in enumerate(operators):
            try:
                iter(row)
            except TypeError:
                raise ValueError(
                    '`operators` must be a matrix of `Operator` objects, `0` '
                    'or `None`, got {!r} (row {} = {!r} is not iterable)'
                    ''.format(operators, i, row))

            if isinstance(row, Operator):
                raise ValueError(
                    '`operators` must be a matrix of `Operator` objects, `0` '
                    'or `None`, but row {} is an `Operator` {!r}'
                    ''.format(i, row))

            if ncols is None:
                ncols = len(row)
            elif len(row) != ncols:
                raise ValueError(
                    'all rows in `operators` must have the same length, but '
                    'length {} of row {} differs from previous common length '
                    '{}'.format(len(row), i, ncols))

            for j, col in enumerate(row):
                if col is None or col is 0:
                    pass
                elif isinstance(col, Operator):
                    irow.append(i)
                    icol.append(j)
                    data.append(col)
                else:
                    raise ValueError(
                        '`operators` must be a matrix of `Operator` objects, '
                        '`0` or `None`, got entry {!r} at ({}, {})'
                        ''.format(col, i, j))

        # Create object array explicitly, threby avoiding erroneous conversion
        # in `coo_matrix.__init__`
        data_arr = np.empty(len(data), dtype=object)
        data_arr[:] = data
        return scipy.sparse.coo_matrix((data_arr, (irow, icol)),
                                       shape=(nrows, ncols))
1059573
public function asColumnMatrix() : Matrix
    {
        $b = [];

        foreach ($this->a as $value) {
            $b[] = [$value];
        }

        return Matrix::quick($b);
    }
306395
def matrix_to_blockmatrix(self, blocksize):
        
        if self.get_width() % blocksize or self.get_height() % blocksize:
            raise ValueError("Number of rows and columns have to be evenly dividable by blocksize")
        selfBlocks = []
        for columnIndex in range(0, self.get_width() - 1, blocksize):
            for rowIndex in range(0, self.get_height() - 1, blocksize):
                currentBlock = []
                for blockRows in self.get_array(False)[columnIndex:columnIndex + blocksize]:
                    currentBlock += blockRows[rowIndex:rowIndex + blocksize]
                selfBlocks.append(Matrix(blocksize, blocksize, currentBlock, rowBased=False))
        return Matrix(self.get_width() / blocksize, self.get_height() / blocksize, selfBlocks, rowBased=False)
770231
def _transform_to_2d(t):
    """"""
    t = np.asarray(t)

    dim = len(t.shape)
    assert dim <= 2

    if dim < 2:
        t = np.atleast_2d(t).T

    return t