prepare_weights#
- skrough.weights.prepare_weights(weights: Optional[Union[int, float, ndarray]], size: int, *, expand_none: Literal[True] = True, normalize: bool = True) ndarray[source]#
- skrough.weights.prepare_weights(weights: Optional[Union[int, float, ndarray]], size: Optional[int] = None, *, expand_none: Literal[False], normalize: bool = True) Optional[ndarray]
Prepare weights.
Process
weightsinto an array form. The inputweightscan be given as a scalar value or an array-like structure of values. The following cases are handled in the function:weightscan beintorfloat- uniform output ofweights(scalar)value repeated
sizetimes is produced
weightscan benp.ndarray- inputweightsare taken as is and in this casesizeparameter is ignored
Additional normalization step (using
normalize_weights()function) is performed for the above result whennormalize == True. All the remarks ofnormalize_weights()applies when negative values are present. In such a case the function will not produce a discrete probability distribution.- Parameters:
weights – Value(s) to be processed.
size – Output length. May be omitted if code:weights is None and expand_none == False.
expand_none – Whether
Noneweights input should be expanded to an array of non-null values. Defaults to True.normalize – Whether to normalize the output values. Defaults to
True.
- Raises:
ValueError – If
size is Noneor less than zero but it is necessary for producing the result. E.g.,weightsis one ofintorfloatorweights is Noneandexpand_none == True.- Returns:
Output weights.