Return the matrix A from a list of Y vectors.
553683
def calc_A(Ys):
    ''''''
    return sum(np.dot(np.reshape(Y, (3,1)), np.reshape(Y, (1, 3)))
            for Y in Ys)
1255453
def compute_affinity_matrix(adjacency_matrix, method='auto', **kwargs):
    """"""
    if method == 'auto':
        method = 'gaussian'
    return Affinity.init(method, **kwargs).affinity_matrix(adjacency_matrix)
966043
def matrix_from_edges(edges):
    ''''''
    max_col = 0
    cols = []
    rows = []
    vals = []
    if type(edges) is defaultdict:
        edge_list = []
        for i, neighbors in edges.items():
            for j in neighbors:
                if i <= j:
                    edge_list.append((i,j))
        edges = edge_list
    for i, edge in enumerate(edges):
        s, t = edge[0], edge[1]
        weight = 1 if len(edge) == 2 else edge[2]
        cols.append(min(s,t))
        cols.append(max(s,t))
        rows.append(i)
        rows.append(i)
        vals.append(weight)
        vals.append(-weight)
        if cols[-1] > max_col:
            max_col = cols[-1]
    return coo_matrix((vals, (rows, cols)), shape=(rows[-1]+1, max_col+1))
347553
function makeMatrix(columns, rows) {
  let matrix = [];
  for (let i = 0; i < columns; i++) {
    let column = [];
    for (let j = 0; j < rows; j++) {
      column.push(0);
    }
    matrix.push(column);
  }
  return matrix;
}
41749
def matrix(self, angle):
        """"""
        _rot_mat = {
            'x': self._x_rot,
            'y': self._y_rot,
            'z': self._z_rot
        }
        return _rot_mat[self.axis](angle)
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)
845386
def submatrix(matrix,i1,i2,j1,j2):
    

    new = []
    for i in range(i1,i2+1):
        new.append(matrix[i][j1:j2+1])
    return _n.array(new)
1332330
def bbox_to_ybox(bbox):
    """"""
    return [
            (bbox[1] + bbox[3]) / 2,
            (bbox[0] + bbox[2]) / 2,
            (bbox[3] - bbox[1]),
            (bbox[2] - bbox[0]),
    ]
739060
def delta_matrix(matrix, clusters):
    
    if isspmatrix(matrix):
        delta = dok_matrix(matrix.shape)
    else:
        delta = np.zeros(matrix.shape)

    for i in clusters :
        for j in permutations(i, 2):
            delta[j] = 1

    return delta
557344
def _get_zoom_mat(sw:float, sh:float, c:float, r:float)->AffineMatrix:
    ""
    return [[sw, 0,  c],
            [0, sh,  r],
            [0,  0, 1.]]
239907
def Rx_matrix(theta):
    """"""
    return np.array([
        [1, 0, 0],
        [0, np.cos(theta), -np.sin(theta)],
        [0, np.sin(theta), np.cos(theta)]
    ])
937124
function arrayToMatrix (a) {
  return { a: a[0], b: a[1], c: a[2], d: a[3], e: a[4], f: a[5] }
}
650896
def _generate_label_matrix(self):
        """"""
        self.L = np.zeros((self.n, self.m))
        self.Y = np.zeros(self.n, dtype=np.int64)
        for i in range(self.n):
            y = choice(self.k, p=self.p) + 1  # Note that y \in {1,...,k}
            self.Y[i] = y
            for j in range(self.m):
                p_j = self.parent.get(j, 0)
                prob_y = self.P_conditional(j, y, p_j, self.L[i, p_j], y)
                prob_0 = self.P_conditional(j, 0, p_j, self.L[i, p_j], y)
                p = np.ones(self.k + 1) * (1 - prob_y - prob_0) / (self.k - 1)
                p[0] = prob_0
                p[y] = prob_y
                self.L[i, j] = choice(self.k + 1, p=p)
440109
private static double ax(Matrix A, double[] x, double[] y, double p) {
        A.ax(x, y);

        if (p != 0.0) {
            for (int i = 0; i < y.length; i++) {
                y[i] -= p * x[i];
            }
        }

        double lambda = y[0];
        for (int i = 1; i < y.length; i++) {
            if (Math.abs(y[i]) > Math.abs(lambda)) {
                lambda = y[i];
            }
        }

        for (int i = 0; i < y.length; i++) {
            x[i] = y[i] / lambda;
        }

        return lambda;
    }
1337119
def get_matrix(self):
        
        return np.array([ self.get_row_list(i) for i in range(self.row_count()) ])
661758
def to_matrix(self, n_qubits=-1):
        """"""
        if n_qubits == -1:
            n_qubits = self.max_n() + 1
        mat = I.to_matrix(n_qubits)
        for op in self.ops:
            if op.is_identity:
                continue
            mat = mat @ op.to_matrix(n_qubits)
        return mat * self.coeff
166088
def _get_kriging_matrix(self, n):
        """"""

        xyz = np.concatenate((self.X_ADJUSTED[:, np.newaxis],
                              self.Y_ADJUSTED[:, np.newaxis],
                              self.Z_ADJUSTED[:, np.newaxis]), axis=1)
        d = cdist(xyz, xyz, 'euclidean')
        a = np.zeros((n+1, n+1))
        a[:n, :n] = - self.variogram_function(self.variogram_model_parameters, d)
        np.fill_diagonal(a, 0.)
        a[n, :] = 1.0
        a[:, n] = 1.0
        a[n, n] = 0.0

        return a