Convert vectors to column matrices, to always have a 2d shape.
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
231739
def sparse(numRows, numCols, colPtrs, rowIndices, values):
        
        return SparseMatrix(numRows, numCols, colPtrs, rowIndices, values)
126720
def scatter_blocks_2d(x, indices, shape):
  """"""
  x_shape = common_layers.shape_list(x)
  # [length, batch, heads, dim]
  x_t = tf.transpose(
      tf.reshape(x, [x_shape[0], x_shape[1], -1, x_shape[-1]]), [2, 0, 1, 3])
  x_t_shape = common_layers.shape_list(x_t)
  indices = tf.reshape(indices, [-1, 1])
  scattered_x = tf.scatter_nd(indices, x_t, x_t_shape)
  scattered_x = tf.transpose(scattered_x, [1, 2, 0, 3])
  return tf.reshape(scattered_x, shape)
576669
function flatten(matrix) {
    const res = [];

    // If the given matrix is not a matrix but a scalar.
    if (!Array.isArray(matrix)) {
        matrix = [
            [matrix]
        ];
    }

    matrix.forEach((row) => {
        // If the given matrix is a vector.
        if (!Array.isArray(row)) {
            row = [row];
        }

        row.forEach((elem) => {
            res.push(elem.real);
            res.push(elem.imag);
        });
    });
    return res;
}
75116
def to_matrix(np_array):
    
    if len(np_array.shape) == 2:
        return Matrices.dense(np_array.shape[0],
                              np_array.shape[1],
                              np_array.ravel())
    else:
        raise Exception("An MLLib Matrix can only be created from a two-dimensional " +
                        "numpy array, got {}".format(len(np_array.shape)))
118480
function subMatrix (data, numRows, numCols, row, col) {
  var sub = []

  for (var i = 0; i < numRows; i++) {
    for (var j = 0; j < numCols; j++) {
      if ((i !== row) && (j !== col)) {
        sub.push(data[matrixToArrayIndex(i, j, numCols)])
      }
    }
  }

  return sub
}
311851
def get_matrix(self, indices):
        """"""
        new = numpy.empty(self.samples1.shape)
        for idx in range(len(indices)):
            if indices[idx]:
                new[idx] = self.samples1[idx]
            else:
                new[idx] = self.samples2[idx]

        if self.poly:
            new = self.poly(*new)
        return new
769455
public static Basic2DMatrix constant(int rows, int columns, double constant) {
        double[][] array = new double[rows][columns];

        for (int i = 0; i < rows; i++) {
            Arrays.fill(array[i], constant);
        }

        return new Basic2DMatrix(array);
    }
913905
def matrix(self):
        """"""
        result = np.identity(4, float)
        result[0:3, 0:3] = self.r
        return result
1258208
public static <T extends DoubleVector> Matrix asMatrix(List<T> vectors) {
        return new ListMatrix<T>(vectors);
    }
404678
public function dot(Vector $b) : ColumnVector
    {
        if ($this->n !== $b->size()) {
            throw new DimensionalityMismatchException('Matrix A requires'
                . " $this->n elements but Vector B has {$b->size()}.");
        }

        return $this->matmul($b->asColumnMatrix())->columnAsVector(0);
    }
1115770
def as_2d(self):
        
        if not self.isdiagonal:
            return self.x
        return np.diag(self.x.flatten())
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)
1147310
def _reshape_m_vecs(self):
        """"""
        
        lst = []
        for n in xrange(0, self.nmax + 1):
            mlst = []
            if n <= self.mmax:
                nn = n
            else:
                nn = self.mmax            
            for m in xrange(-nn, nn + 1):
                mlst.append(self.__getitem__((n, m)))
            lst.append(mlst)
        return lst
1334466
function (t) {
        var p = someVectorAt(this.shape, t, true);
        return vec2.normalize(p, p);
    }
367170
public static Basic2DMatrix from1DArray(int rows, int columns, double[] array) {
        double[][] array2D = new double[rows][columns];

        for (int i = 0; i < rows; i++) {
            System.arraycopy(array, i * columns, array2D[i], 0, columns);
        }

        return new Basic2DMatrix(array2D);
    }
1182020
function(matrix) {
  const rows = matrix.length;
  const columns = matrix[0].length;
  const res = [];
  for (let row = 0; row < rows; ++row) {
    res.push([]);
    for (let column = 0; column < columns; ++column) {
      res[row][column] = matrix[column][columns - row - 1];
    }
  }
  return res;
}