Compute weights, given a scale or time-frequency representation
        :param other: A time-frequency representation, or a scale
        :return: a numpy array of weights
421539
def weights(self, other):
        
        try:
            return self._wdata(other)
        except AttributeError:
            frequency_dim = other.dimensions[-1]
            return self._wdata(frequency_dim.scale)
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];
			}
		}
	}
152848
def weighted(weights, sample_size, with_replacement=False):
        
        assert sample_size <= len(weights), "The sample size must be smaller \
than or equal to the number of weights it's taken from."

        # Convert weights to floats
        weights = [float(w) for w in weights]
        weight_indexes = list(range(0, len(weights)))

        samples = []
        while len(samples) < sample_size:
            # Choice a weight
            sample = OneOf.weighted(weights)

            # Add the choosen weight to our samples
            samples.append(weight_indexes[sample])

            if not with_replacement:
                # Remove the weight from the list of weights we can select from
                del weights[sample]
                del weight_indexes[sample]

        return samples
250209
def scale_transform(t, scale):
    
    if isinstance(scale, float) or isinstance(scale, int):
        scale = [scale, scale, scale]

    if _is_indexable(t[0]):
        return [[t[0][0] * scale[0], t[0][1] * scale[1], t[0][2] * scale[2]],
                t[1]]
    else:
        return [t[0] * scale[0], t[1] * scale[1], t[2] * scale[2]]
905781
def _compute(self, data):
        """"""
        local_ts = self._local_ts(*data)
        dt = local_ts[internal_names.TIME_WEIGHTS_STR]
        # Convert dt to units of days to prevent overflow
        dt = dt / np.timedelta64(1, 'D')
        return local_ts, dt
1023663
def build_weights(realizations, imt_dt):
    
    arr = numpy.zeros((len(realizations), len(imt_dt.names)))
    for m, imt in enumerate(imt_dt.names):
        arr[:, m] = [rlz.weight[imt] for rlz in realizations]
    return arr
722333
def compute_weight(self, r, ytr=None, mask=None):
        
        ytr = self._ytr if ytr is None else ytr
        mask = self._mask if mask is None else mask
        return compute_weight(r, ytr, mask)
937269
def _avg(value1, value2, weight):
        
        if value1 is None:
            return value2
        if value2 is None:
            return value1
        return value2 * weight + value1 * (1 - weight)
1096400
def _iand(self, other):
		
		# TODO do we have to create a bag from the other first?
		if not isinstance(other, _basebag):
			other = self._from_iterable(other)
		for elem, old_count in set(self.counts()):
			other_count = other.count(elem)
			new_count = min(other_count, old_count)
			self._set_count(elem, new_count)
		return self
952457
def non_position_scales(self):
        
        l = [s for s in self
             if not ('x' in s.aesthetics) and not ('y' in s.aesthetics)]
        return Scales(l)
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
190627
def _get_value_type(self, other):
        
        if self.values:
            return type(self.values[0])
        elif isinstance(other, TimeSeries) and other.values:
            return type(other.values[0])
        else:
            raise ValueError('Cannot perform arithmetic on empty time series.')
949244
def get_weights(self):
        
        if self.is_trained() is False:
            # print("Model not fitted yet. Use object.fit() to fit the model.")
            return None

        var_res = self._var_res
        weights = self._var_res_to_weights(var_res)
        # save to the side
        weights["final_bias_fit"] = weights["final_bias"]
        weights["feature_weights_fit"] = weights["feature_weights"]

        return weights
673800
def compute_stats(array, stats, weights):
    
    result = numpy.zeros((len(stats),) + array.shape[1:], array.dtype)
    for i, func in enumerate(stats):
        result[i] = apply_stat(func, array, weights)
    return result
1136286
def glb(self, other):
        
        return self.__class__(
            [
                min(self.lower, other.lower),
                min(self.upper, other.upper)
            ],
            lower_inc=self.lower_inc if self < other else other.lower_inc,
            upper_inc=self.upper_inc if self > other else other.upper_inc,
        )
1173600
def step(weights, duration):
    

    dt = duration / len(weights)

    def activate(t, dt):
        """This function returns 1 if t is in [0, dt[ and 0 otherwise.

        :param float t: current time
        :param float dt: time step
        """
        return 0 <= t < dt

    return (lambda t: sum([w * activate(t - i * dt, dt) for i, w in enumerate(weights)]))
313923
def _add_datetime_arraylike(self, other):
        
        if isinstance(other, np.ndarray):
            # At this point we have already checked that dtype is datetime64
            from pandas.core.arrays import DatetimeArray
            other = DatetimeArray(other)

        # defer to implementation in DatetimeArray
        return other + self