row_center[i] =
        sum{j in observed[i, :]}{
            (1 / column_scale[j]) * (X[i, j] - column_center[j])
        }
        ------------------------------------------------------------
        sum{j in observed[i, :]}{1 / column_scale[j]}
356031
def estimate_row_means(
            self,
            X,
            observed,
            column_means,
            column_scales):
        

        n_rows, n_cols = X.shape

        column_means = np.asarray(column_means)
        if len(column_means) != n_cols:
            raise ValueError("Expected length %d but got shape %s" % (
                n_cols, column_means.shape))
        X = X - column_means.reshape((1, n_cols))
        column_weights = 1.0 / column_scales
        X *= column_weights.reshape((1, n_cols))
        row_means = np.zeros(n_rows, dtype=X.dtype)
        row_residual_sums = np.nansum(X, axis=1)
        for i in range(n_rows):
            row_mask = observed[i, :]
            sum_weights = column_weights[row_mask].sum()
            row_means[i] = row_residual_sums[i] / sum_weights
        return row_means
1210915
def _K(m):
    
    M = m*(m - 1)//2
    K = np.zeros((M, m**2), dtype=np.int64)
    row = 0
    for j in range(1, m):
        col = (j - 1)*m + j
        s = m - j
        K[row:(row+s), col:(col+s)] = np.eye(s)
        row += s
    return K
42414
def row_coordinates(self, X):
        """"""
        utils.validation.check_is_fitted(self, 'V_')

        _, row_names, _, _ = util.make_labels_and_names(X)

        if isinstance(X, pd.SparseDataFrame):
            X = X.to_coo().astype(float)
        elif isinstance(X, pd.DataFrame):
            X = X.to_numpy()

        if self.copy:
            X = X.copy()

        # Normalise the rows so that they sum up to 1
        if isinstance(X, np.ndarray):
            X = X / X.sum(axis=1)[:, None]
        else:
            X = X / X.sum(axis=1)

        return pd.DataFrame(
            data=X @ sparse.diags(self.col_masses_.to_numpy() ** -0.5) @ self.V_.T,
            index=row_names
        )
992175
public static void byColumn(Matrix m) {
        for (int i = 0; i < m.columns(); ++i) {
            double colSum = 0;
            for (int j = 0; j < m.rows(); ++j)
                colSum += m.get(j,i);

            // Skip columns whose sume is zero.
            if (colSum == 0) 
                continue;
            for (int j = 0; j < m.rows(); ++j)
                m.set(j,i, m.get(j,i) / colSum);
        }
    }
821190
def centroid(X):
    
    C = np.sum(X, axis=0) / len(X)
    return C
1261065
def _inner(x, y, axis=-1):
    """"""

    return cp.sum(x * y, axis=axis, keepdims=True)
342958
public static double[] colSums (RealMatrix matrix) {
        // Declare and initialize the return value:
        double[] retval = new double[matrix.getColumnDimension()];

        // Iterate over columns and compute totals:
        for (int col = 0; col < matrix.getColumnDimension(); col++) {
            for (int row = 0; row < matrix.getRowDimension(); row++) {
                retval[col] += matrix.getEntry(row, col);
            }
        }

        // Done, return col sums:
        return retval;
    }
1278352
function rowPluckB(product, left, rowIndex) {
  var columns = left.columns;
  var rowBase = columns * rowIndex;
  for (var column = 0; column < columns; column++) {
    left.deltas[rowBase + column] = product.deltas[column];
  }
}
387987
def func(data_row, wait):
    ''' 
    '''
    time.sleep(wait)
    data_row['sum'] = data_row['col_1'] + data_row['col_2']
    return data_row
618966
def sum(self):
        
        return self._constructor(self.values.sum(axis=self.baseaxes, keepdims=True))
352983
def average(self, rows: List[Row], column: NumberColumn) -> Number:
        
        cell_values = [row.values[column.name] for row in rows]
        if not cell_values:
            return 0.0  # type: ignore
        return sum(cell_values) / len(cell_values)
780374
function cluster(k) {
                var Centroids = this.createCentroids(k);
                var LastDistances = Matrix$d.Zero(this.Observations.rows(), this.Observations.cols());
                var Distances = this.distanceFrom(Centroids);
                var Groups;

                while(!(LastDistances.eql(Distances))) {
                Groups = Distances.minColumnIndexes();
                LastDistances = Distances;

                var newCentroids = [];

                for(var i = 1; i <= Centroids.rows(); i++) {
                    var centroid = [];

                    for(var j = 1; j <= Centroids.cols(); j++) {
                    var sum = 0;
                    var count = 0;

                    for(var l = 1; l <= this.Observations.rows(); l++) {
                        if(Groups.e(l) == i) {
                        count++;
                        sum += this.Observations.e(l, j);
                        }
                    }

                    centroid.push(sum / count);
                    }

                    newCentroids.push(centroid);
                }

                Centroids = $M(newCentroids);
                Distances = this.distanceFrom(Centroids);
                }

                return Groups;
            }
1120441
def sum(a, axis=-1):
    """"""
    d = a.d
    crs = _vector.vector.to_list(a.tt if isinstance(a, _matrix.matrix) else a)
    if axis < 0:
        axis = range(a.d)
    elif isinstance(axis, int):
        axis = [axis]
    axis = list(axis)[::-1]
    for ax in axis:
        crs[ax] = _np.sum(crs[ax], axis=1)
        rleft, rright = crs[ax].shape
        if (rleft >= rright or rleft < rright and ax + 1 >= d) and ax > 0:
            crs[ax - 1] = _np.tensordot(crs[ax - 1], crs[ax], axes=(2, 0))
        elif ax + 1 < d:
            crs[ax + 1] = _np.tensordot(crs[ax], crs[ax + 1], axes=(1, 0))
        else:
            return _np.sum(crs[ax])
        crs.pop(ax)
        d -= 1
    return _vector.vector.from_list(crs)
1312668
def normalize_array(a,direction="column"):
    
    b = a.copy()
    if(direction == "column"):
        sums = np.sum(b,0)
        return np.nan_to_num(b/sums)
    elif(direction == "row"):
        sums =np.sum(b,1)
        return  np.nan_to_num((b.transpose() / sums).transpose())
    elif(direction == "all"):
        sums = np.sum(b)
        return np.nan_to_num(b / sums)
    else:
        print "Error non existing normalization"
        return b
1347660
function findLargestInCol (M, i, startAtRow = 0) {
  let me = M.elements;
  let n = M.dimension;
  let offset = i * n;
  let maxIdx = startAtRow;
  let maxVal = _Math.abs(me[offset + maxIdx]);
  for (let i = maxIdx + 1; i < n; ++i) {
    let val = _Math.abs(me[offset + i]);
    if (val > maxVal) {
      maxIdx = i;
      maxVal = val;
    }
  }
  return maxIdx;
}
963767
def rowcol(x, y, affine, op=math.floor):
    
    r = int(op((y - affine.f) / affine.e))
    c = int(op((x - affine.c) / affine.a))
    return r, c
1019544
public void similar(IMatrix U, IMatrix result) {
        if ((result.rows != U.columns) || (result.columns != U.columns)) result.reshape(U.columns, U.columns);

        double realsum, imagsum, realinnersum, imaginnersum;
        for (int i = 0; i < U.columns; i++)
            for (int j = 0; j < U.columns; j++) {
                realsum = 0d;
                imagsum = 0d;
                for (int k = 0; k < U.columns; k++) {
                    realinnersum = 0d;
                    imaginnersum = 0d;
                    for (int l = 0; l < U.columns; l++) {
                        realinnersum += realmatrix[k][l] * U.realmatrix[l][j] - imagmatrix[k][l] * U.imagmatrix[l][j];
                        imaginnersum += realmatrix[k][l] * U.imagmatrix[l][j] + imagmatrix[k][l] * U.realmatrix[l][j];
                    }
                    realsum += U.realmatrix[k][i] * realinnersum - U.imagmatrix[k][i] * imaginnersum;
                    imagsum += U.realmatrix[k][i] * imaginnersum + U.imagmatrix[k][i] * realinnersum;
                }
                result.realmatrix[i][j] = realsum;
                result.imagmatrix[i][j] = imagsum;
            }
    }