Compute neighbor weights for GeoRaster.
        See help(gr.raster_weights) for options

        Usage:
        geo.raster_weights(rook=True)
328927
def raster_weights(self, **kwargs):
        
        if self.weights is None:
            self.weights = raster_weights(self.raster, **kwargs)
        pass
650721
def neighbors(self, node, diagonal_movement=DiagonalMovement.never):
        
        x = node.x
        y = node.y
        neighbors = []
        s0 = d0 = s1 = d1 = s2 = d2 = s3 = d3 = False

        # ↑
        if self.walkable(x, y - 1):
            neighbors.append(self.nodes[y - 1][x])
            s0 = True
        # →
        if self.walkable(x + 1, y):
            neighbors.append(self.nodes[y][x + 1])
            s1 = True
        # ↓
        if self.walkable(x, y + 1):
            neighbors.append(self.nodes[y + 1][x])
            s2 = True
        # ←
        if self.walkable(x - 1, y):
            neighbors.append(self.nodes[y][x - 1])
            s3 = True

        if diagonal_movement == DiagonalMovement.never:
            return neighbors

        if diagonal_movement == DiagonalMovement.only_when_no_obstacle:
            d0 = s3 and s0
            d1 = s0 and s1
            d2 = s1 and s2
            d3 = s2 and s3
        elif diagonal_movement == DiagonalMovement.if_at_most_one_obstacle:
            d0 = s3 or s0
            d1 = s0 or s1
            d2 = s1 or s2
            d3 = s2 or s3
        elif diagonal_movement == DiagonalMovement.always:
            d0 = d1 = d2 = d3 = True

        # ↖
        if d0 and self.walkable(x - 1, y - 1):
            neighbors.append(self.nodes[y - 1][x - 1])

        # ↗
        if d1 and self.walkable(x + 1, y - 1):
            neighbors.append(self.nodes[y - 1][x + 1])

        # ↘
        if d2 and self.walkable(x + 1, y + 1):
            neighbors.append(self.nodes[y + 1][x + 1])

        # ↙
        if d3 and self.walkable(x - 1, y + 1):
            neighbors.append(self.nodes[y + 1][x - 1])

        return neighbors
800093
def get_interp_weights(nside, theta, phi=None, nest=False, lonlat=False):
    
    # if phi is not given, theta is interpreted as pixel number
    if phi is None:
        theta, phi = pix2ang(nside, ipix=theta, nest=nest)

    lon, lat = _healpy_to_lonlat(theta, phi, lonlat=lonlat)
    return bilinear_interpolation_weights(lon, lat, nside, order='nested' if nest else 'ring')
1128427
protected void computeWeights(int numSamples, double numSigmas) {
		weights = new float[ numSamples*numSamples ];

		float w[] = new float[ numSamples ];
		for( int i = 0; i < numSamples; i++ ) {
			float x = i/(float)(numSamples-1);
			w[i] = (float) UtilGaussian.computePDF(0, 1, 2f*numSigmas * (x - 0.5f));
		}

		for( int y = 0; y < numSamples; y++ ) {
			for( int x = 0; x < numSamples; x++ ) {
				weights[y*numSamples + x] = w[y]*w[x];
			}
		}
	}
354407
def join(rasters):
    

    raster = rasters[0]  # using the first raster to understand what is the type of data we have
    mask_band = None
    nodata = None
    with raster._raster_opener(raster.source_file) as r:
        nodata = r.nodata
        mask_flags = r.mask_flag_enums
    per_dataset_mask = all([rasterio.enums.MaskFlags.per_dataset in flags for flags in mask_flags])
    if per_dataset_mask and nodata is None:
        mask_band = 0
    return GeoRaster2.from_rasters(rasters, relative_to_vrt=False, nodata=nodata, mask_band=mask_band)
975495
def _slice_weights(self, arr, li, lh):
        """"""
        args = {}
        gate_names = self._gate_names
        directions = self._directions

        b = len(directions)
        p = 0
        for layer in range(self._num_layers):
            for direction in directions:
                for gate in gate_names:
                    name = '%s%s%d_i2h%s_weight'%(self._prefix, direction, layer, gate)
                    if layer > 0:
                        size = b*lh*lh
                        args[name] = arr[p:p+size].reshape((lh, b*lh))
                    else:
                        size = li*lh
                        args[name] = arr[p:p+size].reshape((lh, li))
                    p += size
                for gate in gate_names:
                    name = '%s%s%d_h2h%s_weight'%(self._prefix, direction, layer, gate)
                    size = lh**2
                    args[name] = arr[p:p+size].reshape((lh, lh))
                    p += size

        for layer in range(self._num_layers):
            for direction in directions:
                for gate in gate_names:
                    name = '%s%s%d_i2h%s_bias'%(self._prefix, direction, layer, gate)
                    args[name] = arr[p:p+lh]
                    p += lh
                for gate in gate_names:
                    name = '%s%s%d_h2h%s_bias'%(self._prefix, direction, layer, gate)
                    args[name] = arr[p:p+lh]
                    p += lh

        assert p == arr.size, "Invalid parameters size for FusedRNNCell"
        return args
141149
def _compute_weights(self):
        

        n = self.n
        k = self.kappa

        self.Wm = np.full(2*n+1, .5 / (n + k))
        self.Wm[0] = k / (n+k)
        self.Wc = self.Wm
221119
def neighborhood_probability(self, threshold, radius):
        
        weights = disk(radius, dtype=np.uint8)
        thresh_data = np.zeros(self.data.shape[1:], dtype=np.uint8)
        neighbor_prob = np.zeros(self.data.shape, dtype=np.float32)
        for t in np.arange(self.data.shape[0]):
            thresh_data[self.data[t] >= threshold] = 1
            maximized = fftconvolve(thresh_data, weights, mode="same")
            maximized[maximized > 1] = 1
            maximized[maximized < 1] = 0
            neighbor_prob[t] = fftconvolve(maximized, weights, mode="same")
            thresh_data[:] = 0
        neighbor_prob[neighbor_prob < 1] = 0
        neighbor_prob /= weights.sum()
        return neighbor_prob
1081101
def perimeter(patch, world_size=(60, 60),
              neighbor_func=get_rook_neighbors_toroidal):
    
    edge = 0
    patch = set([tuple(i) for i in patch])
    for cell in patch:
        neighbors = neighbor_func(cell, world_size)
        neighbors = [n for n in neighbors if n not in patch]
        edge += len(neighbors)

    return edge
1149854
def neighbors(self) -> List['Node']:
        
        self._load_neighbors()
        return [edge.source if edge.source != self else edge.target
                for edge in self._neighbors.values()]
775504
def adjacent(geohash, direction):
  """"""
  # Based on an MIT licensed implementation by Chris Veness from:
  #   http://www.movable-type.co.uk/scripts/geohash.html
  assert direction in 'nsew', "Invalid direction: %s"%direction
  assert geohash, "Invalid geohash: %s"%geohash
  neighbor = {
    'n': [ 'p0r21436x8zb9dcf5h7kjnmqesgutwvy', 'bc01fg45238967deuvhjyznpkmstqrwx' ],
    's': [ '14365h7k9dcfesgujnmqp0r2twvyx8zb', '238967debc01fg45kmstqrwxuvhjyznp' ],
    'e': [ 'bc01fg45238967deuvhjyznpkmstqrwx', 'p0r21436x8zb9dcf5h7kjnmqesgutwvy' ],
    'w': [ '238967debc01fg45kmstqrwxuvhjyznp', '14365h7k9dcfesgujnmqp0r2twvyx8zb' ]
  }
  border = {
    'n': [ 'prxz',     'bcfguvyz' ],
    's': [ '028b',     '0145hjnp' ],
    'e': [ 'bcfguvyz', 'prxz'     ],
    'w': [ '0145hjnp', '028b'     ]
  }
  last = geohash[-1]
  parent = geohash[0:-1]
  t = len(geohash) % 2
  # Check for edge cases
  if (last in border[direction][t]) and (parent):
    parent = adjacent(parent, direction)
  return parent + BASESEQUENCE[neighbor[direction][t].index(last)]
456956
def neighbors(geohash):
  """"""
  return {
    'n':  adjacent(geohash, 'n'),
    'ne': adjacent(adjacent(geohash, 'n'), 'e'),
    'e':  adjacent(geohash, 'e'),
    'se': adjacent(adjacent(geohash, 's'), 'e'),
    's':  adjacent(geohash, 's'),
    'sw': adjacent(adjacent(geohash, 's'), 'w'),
    'w':  adjacent(geohash, 'w'),
    'nw': adjacent(adjacent(geohash, 'n'), 'w'),
    'c':  geohash
  }
981516
def reweight(self, weight, edges=None, copy=False):
    ''''''
    if not self.is_weighted():
      warnings.warn('Cannot supply weights for unweighted graph; '
                    'ignoring call to reweight')
      return self
    if edges is None:
      return self._update_edges(weight, copy=copy)
    ii, jj = self.pairs()[edges].T
    return self.add_edges(ii, jj, weight=weight, symmetric=False, copy=copy)
750720
def _compute_weights(self, X, rs):
        """"""

        # use supplied weights if present
        weights = self._get_user_components('weights')
        if (weights is None):
            n_features = X.shape[1]
            hw_size = (n_features, self.n_hidden)
            weights = rs.normal(size=hw_size)

        self.components_['weights'] = weights
1252299
function rankWeights(g, fixed, movable) {
    var fixedPos = dig_dot_layout_orderMap(g, fixed);
    var weights = {};
    for (var i = 0; i < movable.length; ++i) {
      var weight = -1;
      var u = movable[i];
      var sucs = g.neighbors(movable[i], "both").filter(function(v) { return v in fixedPos; });
      if (sucs.length > 0) {
        weight = 0;
        sucs.forEach(function(v) {
          weight += fixedPos[v];
        });
        weight = weight / sucs.length;
      }
      weights[u] = weight;
    }
    return weights;
  }
465066
def pysal_Geary(self, **kwargs):
        
        if self.weights is None:
            self.raster_weights(**kwargs)
        rasterf = self.raster.flatten()
        rasterf = rasterf[rasterf.mask==False]
        self.Geary = pysal.Geary(rasterf, self.weights, **kwargs)
1227278
def eight_neighbors(self, row, col):
        
        ans = []
        if row > 0:
            ans.append((row - 1, col))
        if row < self.grid_height - 1:
            ans.append((row + 1, col))
        if col > 0:
            ans.append((row, col - 1))
        if col < self.grid_width - 1:
            ans.append((row, col + 1))
        if (row > 0) and (col > 0):
            ans.append((row - 1, col - 1))
        if (row > 0) and (col < self.grid_width - 1):
            ans.append((row - 1, col + 1))
        if (row < self.grid_height - 1) and (col > 0):
            ans.append((row + 1, col - 1))
        if (row < self.grid_height - 1) and (col < self.grid_width - 1):
            ans.append((row + 1, col + 1))
        return ans