一个简单易用的Python加权计算库,提供多种加权算法
Project description
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天)
返回: 时间衰减加权结果
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
weights_calc-1.0.1.tar.gz
(2.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file weights_calc-1.0.1.tar.gz.
File metadata
- Download URL: weights_calc-1.0.1.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.9 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5099ef18b737645f89624b0e18d4c69d34da8b19a364dbeb49a661f105eb99dc
|
|
| MD5 |
e10201c22516b42974262377f69ec3a4
|
|
| BLAKE2b-256 |
4ca532458f189b380b5d144a6d12b29458390776a5823cf2dc9a8fa1ceb1f358
|
File details
Details for the file weights_calc-1.0.1-py3-none-any.whl.
File metadata
- Download URL: weights_calc-1.0.1-py3-none-any.whl
- Upload date:
- Size: 3.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.9 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4532431bac6a074a753f1e7fe1d98666f637ba6ec2a4920c98bb9f245927f060
|
|
| MD5 |
35e9868d2d6b91660aa77cb2fd2e5d1c
|
|
| BLAKE2b-256 |
4826de99c9fc74a5ccb7a9ab79c48912cf48372732654ea9025e22ea55ab4831
|