Weights-Calc
一个简单易用的Python加权计算库,提供多种加权算法
安装
pip install weights
功能
- 加权计算: 基础的加权平均计算
- 加权随机: 根据权重进行随机选择
- 时间衰减加权: 基于时间的指数衰减加权
使用方法
导入
方法1
import importlib
Weights_Calc = importlib.import_module('Weights-Calc')
方法2
Weights_Calc = __import__('Weights-Calc')
加权计算
values = [10, 20, 30]
weights = [0.2, 0.3, 0.5]
result = Weights_Calc.weighted_calculate(values, weights)
print(result) # 输出: 23.0
加权随机
items = ['A', 'B', 'C']
weights = [1, 2, 3]
selected = Weights_Calc.weighted_random(items, weights)
print(selected) # 输出: ['B'] (概率更高)
时间衰减加权
values = [100, 200, 300]
dates = [1, 5, 10] # 时间点
half_life = 7 # 半衰期
result = Weights_Calc.time_decay_weighted(values, dates, half_life)
print(result)
API参考
weighted_calculate(values, weights)
计算加权结果。
参数:
values: 数值列表weights: 权重列表
返回: 加权计算结果
weighted_random(items, weights)
根据权重随机选择项目。
参数:
items: 待选择的项目列表weights: 对应的权重列表
返回: 随机选择的项目列表
time_decay_weighted(values, dates, half_life_days=7)
基于时间衰减的加权计算。
参数:
values: 数值列表dates: 时间点列表half_life_days: 半衰期天数(默认7天)
返回: 时间衰减加权结果
Metadata
Release files for Weights-Calc 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| weights_calc-1.0.1.tar.gz | 2.8 kB | Without provenance | Details for weights_calc-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| weights_calc-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for weights_calc-1.0.1-py3-none-any.whl |
Total release size: 6.0 kB
Release files / weights_calc-1.0.1.tar.gz
| Download URL | weights_calc-1.0.1.tar.gz |
|---|---|
| Size | 2.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5099ef18b737645f89624b0e18d4c69d34da8b19a364dbeb49a661f105eb99dc
|
|
BLAKE2b-256 checksum How to use checksums |
4ca532458f189b380b5d144a6d12b29458390776a5823cf2dc9a8fa1ceb1f358
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.12.9 Windows/11
|
Release files / weights_calc-1.0.1-py3-none-any.whl
| Download URL | weights_calc-1.0.1-py3-none-any.whl |
|---|---|
| Size | 3.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4532431bac6a074a753f1e7fe1d98666f637ba6ec2a4920c98bb9f245927f060
|
|
BLAKE2b-256 checksum How to use checksums |
4826de99c9fc74a5ccb7a9ab79c48912cf48372732654ea9025e22ea55ab4831
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.12.9 Windows/11
|
Security for Weights-Calc 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.