meanlib


Namemeanlib JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/PinkPantherPC/meanlib.git
SummaryA Python package for calculating simple and weighted means, featuring classes for dynamic updates and sliding window functionality.
upload_time2024-08-02 17:34:50
maintainerNone
docs_urlNone
authorTobia Petrolini
requires_python>=3.7
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # meanlib

`meanlib` is a Python library designed to facilitate the computation of various types of means, including simple means, rolling means, and weighted means. It provides easy-to-use classes and functions to update, compute, and retrieve means dynamically as new data becomes available.

## Features

- SimpleMean: Calculate and update a simple arithmetic mean with each new value.
- Mean: Calculate a rolling mean with an optional limit on the number of values stored.
- Weighted Mean Function: Calculate the weighted mean of a list of values.

## Usage

Here are some basic examples of how to use the library.

### Simple Mean Calculation

```python
from meanlib import SimpleMean

# Initialize the SimpleMean object
simple_mean = SimpleMean()

# Update the mean with new values
simple_mean.update(5)
simple_mean.update(10)
print(simple_mean.get_mean())  # Output: 7.5
```

### Rolling Mean with a Maximum Limit

```python
from meanlib import Mean

# Initialize the Mean object with a maximum of 3 values
mean = Mean(max_size=3)

# Update the mean with new values
mean.update(10)
mean.update(20)
mean.update(30)
print(mean.get_mean())  # Output: 20.0

# Adding another value, which will remove the oldest value (10)
mean.update(40)
print(mean.get_mean())  # Output: 30.0
```

### Weighted Mean Calculation

```python
from meanlib import weighted_mean

# Define values and their corresponding weights
values = [1, 2, 3, 4]
weights = [1, 2, 1, 1]

# Calculate the weighted mean
wm = weighted_mean(values, weights)
print(wm)  # Output: 2.5
```
## API Reference

### `weighted_mean(values, weights)`

Calculates the weighted mean of a list of values.

#### Parameters

- `values` (list or array-like): The list of values for which the weighted mean is to be calculated.
- `weights` (list or array-like): The list of weights associated with each value.

#### Returns

- `float` or `complex`: The calculated weighted mean.

#### Raises

- `TypeError`: If values or weights are not list or array-like.
- `ValueError`: If values and weights do not have the same length.
- `ZeroDivisionError`: If the total of values is zero.

### `class SimpleMean`

A class for calculating a simple arithmetic mean that can be updated incrementally.

#### `SimpleMean.__init__()`

Initializes a `SimpleMean` object with initial sum and count set to zero.

#### `SimpleMean.update(number)`

Updates the mean with a new value.

#### Parameters:

- `number` (int, float, or complex): The new value to be added to the mean.

#### Returns:

- `float` or `complex`: The updated mean.

#### Raises:

- `TypeError`: If `number` is not of a compatible type.

#### `SimpleMean.get_mean()`

Returns the current mean.

#### Returns:

- `float` or `complex`: The current mean.
- `None`: If the count is zero.

### `class Mean`

A class for calculating a rolling mean with an optional limit on the number of values stored.

#### `Mean.__init__(max_size=None)`

Initializes a `Mean` object.

#### Parameters:

- `max_size` (int or str, optional): The maximum number of values to store in the array. If `None`, there is no limit.

#### Raises:

- `ValueError`: If `max_size` is not an integer or a string of an integer.

#### `Mean.update(number)`

Updates the mean with a new value, maintaining the array size within the maximum limit.

#### Parameters:

- `number` (int, float, or complex): The new value to be added to the mean.

#### Returns:

- `float` or `complex`: The updated mean.

#### Raises:

- `TypeError`: If `number` is not of a compatible type.

#### `Mean.update_list(_list)`

Updates the mean with a list of values, maintaining the array size within the maximum limit.

#### Parameters:

- `_list` (list or tuple): The new value to be added to the mean.

#### Returns:

- `float` or `complex`: The updated mean.
- `None`: If the count is zero.

#### Raises:

- `TypeError`: If an element in `_list` is not of the correct type or if the value is not of a compatible type.

#### `Mean.get_mean()`

Returns the current mean.

#### Returns:

- `float` or `complex`: The current mean.
- `None`: If the count is zero.

## License

This library is licensed under the MIT License.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/PinkPantherPC/meanlib.git",
    "name": "meanlib",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": null,
    "author": "Tobia Petrolini",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/dd/75/7cd293fc00f1ad54f315b866127c9617032f6c561e994f12c06fe8042dc6/meanlib-1.0.0.tar.gz",
    "platform": null,
    "description": "# meanlib\r\n\r\n`meanlib` is a Python library designed to facilitate the computation of various types of means, including simple means, rolling means, and weighted means. It provides easy-to-use classes and functions to update, compute, and retrieve means dynamically as new data becomes available.\r\n\r\n## Features\r\n\r\n- SimpleMean: Calculate and update a simple arithmetic mean with each new value.\r\n- Mean: Calculate a rolling mean with an optional limit on the number of values stored.\r\n- Weighted Mean Function: Calculate the weighted mean of a list of values.\r\n\r\n## Usage\r\n\r\nHere are some basic examples of how to use the library.\r\n\r\n### Simple Mean Calculation\r\n\r\n```python\r\nfrom meanlib import SimpleMean\r\n\r\n# Initialize the SimpleMean object\r\nsimple_mean = SimpleMean()\r\n\r\n# Update the mean with new values\r\nsimple_mean.update(5)\r\nsimple_mean.update(10)\r\nprint(simple_mean.get_mean())  # Output: 7.5\r\n```\r\n\r\n### Rolling Mean with a Maximum Limit\r\n\r\n```python\r\nfrom meanlib import Mean\r\n\r\n# Initialize the Mean object with a maximum of 3 values\r\nmean = Mean(max_size=3)\r\n\r\n# Update the mean with new values\r\nmean.update(10)\r\nmean.update(20)\r\nmean.update(30)\r\nprint(mean.get_mean())  # Output: 20.0\r\n\r\n# Adding another value, which will remove the oldest value (10)\r\nmean.update(40)\r\nprint(mean.get_mean())  # Output: 30.0\r\n```\r\n\r\n### Weighted Mean Calculation\r\n\r\n```python\r\nfrom meanlib import weighted_mean\r\n\r\n# Define values and their corresponding weights\r\nvalues = [1, 2, 3, 4]\r\nweights = [1, 2, 1, 1]\r\n\r\n# Calculate the weighted mean\r\nwm = weighted_mean(values, weights)\r\nprint(wm)  # Output: 2.5\r\n```\r\n## API Reference\r\n\r\n### `weighted_mean(values, weights)`\r\n\r\nCalculates the weighted mean of a list of values.\r\n\r\n#### Parameters\r\n\r\n- `values` (list or array-like): The list of values for which the weighted mean is to be calculated.\r\n- `weights` (list or array-like): The list of weights associated with each value.\r\n\r\n#### Returns\r\n\r\n- `float` or `complex`: The calculated weighted mean.\r\n\r\n#### Raises\r\n\r\n- `TypeError`: If values or weights are not list or array-like.\r\n- `ValueError`: If values and weights do not have the same length.\r\n- `ZeroDivisionError`: If the total of values is zero.\r\n\r\n### `class SimpleMean`\r\n\r\nA class for calculating a simple arithmetic mean that can be updated incrementally.\r\n\r\n#### `SimpleMean.__init__()`\r\n\r\nInitializes a `SimpleMean` object with initial sum and count set to zero.\r\n\r\n#### `SimpleMean.update(number)`\r\n\r\nUpdates the mean with a new value.\r\n\r\n#### Parameters:\r\n\r\n- `number` (int, float, or complex): The new value to be added to the mean.\r\n\r\n#### Returns:\r\n\r\n- `float` or `complex`: The updated mean.\r\n\r\n#### Raises:\r\n\r\n- `TypeError`: If `number` is not of a compatible type.\r\n\r\n#### `SimpleMean.get_mean()`\r\n\r\nReturns the current mean.\r\n\r\n#### Returns:\r\n\r\n- `float` or `complex`: The current mean.\r\n- `None`: If the count is zero.\r\n\r\n### `class Mean`\r\n\r\nA class for calculating a rolling mean with an optional limit on the number of values stored.\r\n\r\n#### `Mean.__init__(max_size=None)`\r\n\r\nInitializes a `Mean` object.\r\n\r\n#### Parameters:\r\n\r\n- `max_size` (int or str, optional): The maximum number of values to store in the array. If `None`, there is no limit.\r\n\r\n#### Raises:\r\n\r\n- `ValueError`: If `max_size` is not an integer or a string of an integer.\r\n\r\n#### `Mean.update(number)`\r\n\r\nUpdates the mean with a new value, maintaining the array size within the maximum limit.\r\n\r\n#### Parameters:\r\n\r\n- `number` (int, float, or complex): The new value to be added to the mean.\r\n\r\n#### Returns:\r\n\r\n- `float` or `complex`: The updated mean.\r\n\r\n#### Raises:\r\n\r\n- `TypeError`: If `number` is not of a compatible type.\r\n\r\n#### `Mean.update_list(_list)`\r\n\r\nUpdates the mean with a list of values, maintaining the array size within the maximum limit.\r\n\r\n#### Parameters:\r\n\r\n- `_list` (list or tuple): The new value to be added to the mean.\r\n\r\n#### Returns:\r\n\r\n- `float` or `complex`: The updated mean.\r\n- `None`: If the count is zero.\r\n\r\n#### Raises:\r\n\r\n- `TypeError`: If an element in `_list` is not of the correct type or if the value is not of a compatible type.\r\n\r\n#### `Mean.get_mean()`\r\n\r\nReturns the current mean.\r\n\r\n#### Returns:\r\n\r\n- `float` or `complex`: The current mean.\r\n- `None`: If the count is zero.\r\n\r\n## License\r\n\r\nThis library is licensed under the MIT License.\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python package for calculating simple and weighted means, featuring classes for dynamic updates and sliding window functionality.",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/PinkPantherPC/meanlib.git"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7cf9b3550b3c5f33cf8f80b7850d021eed023f77cce276a3f44d131f5b69f849",
                "md5": "2430670f1eab26db6ff070696eb83945",
                "sha256": "c0ff0cfad220d96a7a7a7fa77753588b051a261ef4aa846d1b8d4e93a78017ee"
            },
            "downloads": -1,
            "filename": "meanlib-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2430670f1eab26db6ff070696eb83945",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 5265,
            "upload_time": "2024-08-02T17:34:49",
            "upload_time_iso_8601": "2024-08-02T17:34:49.006125Z",
            "url": "https://files.pythonhosted.org/packages/7c/f9/b3550b3c5f33cf8f80b7850d021eed023f77cce276a3f44d131f5b69f849/meanlib-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dd757cd293fc00f1ad54f315b866127c9617032f6c561e994f12c06fe8042dc6",
                "md5": "a93a5357c152b960fc1b633cf45a2166",
                "sha256": "d226fda81030747511eb123136709365856ab5599413ec5985378ed11db86e74"
            },
            "downloads": -1,
            "filename": "meanlib-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a93a5357c152b960fc1b633cf45a2166",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 4595,
            "upload_time": "2024-08-02T17:34:50",
            "upload_time_iso_8601": "2024-08-02T17:34:50.611748Z",
            "url": "https://files.pythonhosted.org/packages/dd/75/7cd293fc00f1ad54f315b866127c9617032f6c561e994f12c06fe8042dc6/meanlib-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-02 17:34:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "PinkPantherPC",
    "github_project": "meanlib",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "meanlib"
}
        
Elapsed time: 0.35678s