================
Numpy Structures
================
.. image:: https://img.shields.io/pypi/v/npstructures.svg
:target: https://pypi.python.org/pypi/npstructures
.. image:: https://github.com/knutdrand/npstructures/actions/workflows/python-install-and-test.yml/badge.svg
:target: https://github.com/knutdrand/npstructures/actions/workflows/python-install-and-test.yml
.. image:: https://readthedocs.org/projects/npstructures/badge/?version=latest
:target: https://npstructures.readthedocs.io/en/latest/?version=latest
:alt: Documentation Status
Simple data structures that augments the numpy library
* Free software: MIT license
* Documentation: https://npstructures.readthedocs.io.
Features
--------
The main feature is the `RaggedArray` class which enables `numpy`-like behaviour and performance for arrays where
the length of the rows differ.
`RaggedArray` is meant as a drop-in replacement for `numpy` when you have arrays with differing row lengths.
As such, familiarity with `numpy` is assumed. The simplest way to construct a `RaggedArray` is from a list of lists::
>>> from npstructures import RaggedArray
>>> ra = RaggedArray([[1, 2], [4, 1, 3, 7], [9], [8, 7, 3, 4]])
A `RaggedArray` can be indexed much like a `numpy` array::
>>> ra[1]
array([4, 1, 3, 7])
>>> ra[1, 3]
7
>>> ra[1:3]
RaggedArray([[4, 1, 3, 7], [9]])
>>> ra[[0, 3]]
RaggedArray([[1, 2], [8, 7, 3, 4]])
>>> ra[0] = [0, 0]
>>> ra
RaggedArray([[0, 0], [4, 1, 3, 7], [9], [8, 7, 3, 4]])
>>> ra[1:3] = [[10], [20]]
>>> ra
RaggedArray([[0, 0], [10, 10, 10, 10], [20], [8, 7, 3, 4]])
>>> ra[[0, 2, 3]] = RaggedArray([[2, 2], [3], [5, 5, 5, 5]])
>>> ra
RaggedArray([[2, 2], [10, 10, 10, 10], [3], [5, 5, 5, 5]])
`numpy ufuncs` can be applied to `RaggedArray` objects::
>>> ra + 1
RaggedArray([[2, 3], [5, 2, 4, 8], [10], [9, 8, 4, 5]])
>>> ra*2
RaggedArray([[2, 4], [8, 2, 6, 14], [18], [16, 14, 6, 8]])
>>> ra + [[1], [10], [100], [1000]]
RaggedArray([[2, 3], [14, 11, 13, 17], [109], [1008, 1007, 1003, 1004]])
>>> ra - (ra*2)
RaggedArray([[-1, -2], [-4, -1, -3, -7], [-9], [-8, -7, -3, -4]])
Some `numpy` functions can be applied to `RaggedArray` objects::
>>> import numpy as np
>>> ra = RaggedArray([[1, 2], [4, 1, 3, 7], [9], [8, 7, 3, 4]])
>>> np.concatenate((ra, ra*10))
RaggedArray([[1, 2], [4, 1, 3, 7], [9], [8, 7, 3, 4], [10, 20], [40, 10, 30, 70], [90], [80, 70, 30, 40]])
>>> np.nonzero(ra>3)
(array([1, 1, 2, 3, 3, 3]), array([0, 3, 0, 0, 1, 3]))
>>> np.ones_like(ra)
RaggedArray([[1, 1], [1, 1, 1, 1], [1], [1, 1, 1, 1]])
In addition to this. `HashTable` and `Counter` provides simple `dict`-like behaviour for `numpy` arrays:
`HashTable` can be used for `dict`-like functionality of `numpy` arrays. The simplest way to construct a `HashTable` is from an array of keys and an array of values (note that the set of keys cannot be modified after the initialization of the object)::
>>> table = HashTable([11, 113, 1191, 11199], [2, 3, 5, 7])
>>> table[11]
array([2])
>>> table[[113, 11199]]
array([3, 7])
>>> table[11]=1000
>>> table
HashTable([ 113 1191 11 11199], [ 3 5 1000 7])
>>> table[[113, 1191]]=2000
>>> table
HashTable([ 113 1191 11 11199], [2000 2000 1000 7])
>>> table[[113, 1191, 11, 11191]] = [1, 2, 3, 4]
>>> table[[113, 1191, 11, 11199]] = [1, 2, 3, 4]
>>> table
HashTable([ 113 1191 11 11199], [1 2 3 4])
`Counter` objects supports counting the occurances of a predefined set of keys in a set of samples. For instance, to count the occurances of `3` and `1` in the list ``[3, 2, 1, 3, 4, 1, 1]``::
>>> from npstructures import Counter
>>> counter = Counter([3, 1])
>>> counter.count([3, 2, 1, 3, 4, 1, 1])
>>> counter
Counter([3 1], [2 3])
Credits
-------
This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.
.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage
=======
History
=======
0.2.0 (2022-06-17)
------------------
* Tested indexing, ufuncs and arrayfunctions with hypothesis
0.1.0 (2021-12-27)
------------------
* First release on PyPI.
Raw data
{
"_id": null,
"home_page": "https://github.com/knutdrand/npstructures",
"name": "npstructures",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "npstructures",
"author": "Knut Rand",
"author_email": "knutdrand@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/f5/72/e2574d0f865879218cbc40a018c4935bb4475c5a8a14b96fd3de21092c5a/npstructures-0.2.19.tar.gz",
"platform": null,
"description": "================\nNumpy Structures\n================\n\n\n.. image:: https://img.shields.io/pypi/v/npstructures.svg\n :target: https://pypi.python.org/pypi/npstructures\n\n.. image:: https://github.com/knutdrand/npstructures/actions/workflows/python-install-and-test.yml/badge.svg\n :target: https://github.com/knutdrand/npstructures/actions/workflows/python-install-and-test.yml\n\n.. image:: https://readthedocs.org/projects/npstructures/badge/?version=latest\n :target: https://npstructures.readthedocs.io/en/latest/?version=latest\n :alt: Documentation Status\n\nSimple data structures that augments the numpy library\n\n\n* Free software: MIT license\n* Documentation: https://npstructures.readthedocs.io.\n\n\nFeatures\n--------\nThe main feature is the `RaggedArray` class which enables `numpy`-like behaviour and performance for arrays where\nthe length of the rows differ.\n\n`RaggedArray` is meant as a drop-in replacement for `numpy` when you have arrays with differing row lengths.\nAs such, familiarity with `numpy` is assumed. The simplest way to construct a `RaggedArray` is from a list of lists::\n\n >>> from npstructures import RaggedArray\n >>> ra = RaggedArray([[1, 2], [4, 1, 3, 7], [9], [8, 7, 3, 4]])\n\nA `RaggedArray` can be indexed much like a `numpy` array::\n\n >>> ra[1]\n array([4, 1, 3, 7])\n >>> ra[1, 3]\n 7\n >>> ra[1:3]\n RaggedArray([[4, 1, 3, 7], [9]])\n >>> ra[[0, 3]]\n RaggedArray([[1, 2], [8, 7, 3, 4]])\n >>> ra[0] = [0, 0]\n >>> ra\n RaggedArray([[0, 0], [4, 1, 3, 7], [9], [8, 7, 3, 4]])\n >>> ra[1:3] = [[10], [20]]\n >>> ra\n RaggedArray([[0, 0], [10, 10, 10, 10], [20], [8, 7, 3, 4]])\n >>> ra[[0, 2, 3]] = RaggedArray([[2, 2], [3], [5, 5, 5, 5]])\n >>> ra\n RaggedArray([[2, 2], [10, 10, 10, 10], [3], [5, 5, 5, 5]])\n\n`numpy ufuncs` can be applied to `RaggedArray` objects::\n\n >>> ra + 1\n RaggedArray([[2, 3], [5, 2, 4, 8], [10], [9, 8, 4, 5]])\n >>> ra*2\n RaggedArray([[2, 4], [8, 2, 6, 14], [18], [16, 14, 6, 8]])\n >>> ra + [[1], [10], [100], [1000]]\n RaggedArray([[2, 3], [14, 11, 13, 17], [109], [1008, 1007, 1003, 1004]])\n >>> ra - (ra*2)\n RaggedArray([[-1, -2], [-4, -1, -3, -7], [-9], [-8, -7, -3, -4]])\n\nSome `numpy` functions can be applied to `RaggedArray` objects::\n\n >>> import numpy as np\n >>> ra = RaggedArray([[1, 2], [4, 1, 3, 7], [9], [8, 7, 3, 4]])\n >>> np.concatenate((ra, ra*10))\n RaggedArray([[1, 2], [4, 1, 3, 7], [9], [8, 7, 3, 4], [10, 20], [40, 10, 30, 70], [90], [80, 70, 30, 40]])\n >>> np.nonzero(ra>3)\n (array([1, 1, 2, 3, 3, 3]), array([0, 3, 0, 0, 1, 3]))\n >>> np.ones_like(ra)\n RaggedArray([[1, 1], [1, 1, 1, 1], [1], [1, 1, 1, 1]])\n\n\nIn addition to this. `HashTable` and `Counter` provides simple `dict`-like behaviour for `numpy` arrays:\n\n`HashTable` can be used for `dict`-like functionality of `numpy` arrays. The simplest way to construct a `HashTable` is from an array of keys and an array of values (note that the set of keys cannot be modified after the initialization of the object)::\n\n >>> table = HashTable([11, 113, 1191, 11199], [2, 3, 5, 7])\n >>> table[11]\n array([2])\n >>> table[[113, 11199]]\n array([3, 7])\n >>> table[11]=1000\n >>> table\n HashTable([ 113 1191 11 11199], [ 3 5 1000 7])\n >>> table[[113, 1191]]=2000\n >>> table\n HashTable([ 113 1191 11 11199], [2000 2000 1000 7])\n >>> table[[113, 1191, 11, 11191]] = [1, 2, 3, 4]\n >>> table[[113, 1191, 11, 11199]] = [1, 2, 3, 4]\n >>> table\n HashTable([ 113 1191 11 11199], [1 2 3 4])\n\n`Counter` objects supports counting the occurances of a predefined set of keys in a set of samples. For instance, to count the occurances of `3` and `1` in the list ``[3, 2, 1, 3, 4, 1, 1]``::\n\n >>> from npstructures import Counter\n >>> counter = Counter([3, 1])\n >>> counter.count([3, 2, 1, 3, 4, 1, 1])\n >>> counter\n Counter([3 1], [2 3])\n\nCredits\n-------\n\nThis package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.\n\n.. _Cookiecutter: https://github.com/audreyr/cookiecutter\n.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage\n\n\n=======\nHistory\n=======\n\n0.2.0 (2022-06-17)\n------------------\n* Tested indexing, ufuncs and arrayfunctions with hypothesis\n\n\n0.1.0 (2021-12-27)\n------------------\n\n* First release on PyPI.\n\n",
"bugtrack_url": null,
"license": "MIT license",
"summary": "Simple data structures that augments the numpy library",
"version": "0.2.19",
"project_urls": {
"Homepage": "https://github.com/knutdrand/npstructures"
},
"split_keywords": [
"npstructures"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2a6bfdbd754e75c16c1da91f159170d2b25e9028f21bbc5d2102028b9912cefb",
"md5": "dbe185716165d33f6383a5e8f9bb8d09",
"sha256": "0d833606978cfd5b01b5fb3b74bb9896a53a1e1f82d4b5cc09def1920e41fdbd"
},
"downloads": -1,
"filename": "npstructures-0.2.19-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "dbe185716165d33f6383a5e8f9bb8d09",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=3.6",
"size": 36360,
"upload_time": "2024-05-31T08:54:04",
"upload_time_iso_8601": "2024-05-31T08:54:04.317572Z",
"url": "https://files.pythonhosted.org/packages/2a/6b/fdbd754e75c16c1da91f159170d2b25e9028f21bbc5d2102028b9912cefb/npstructures-0.2.19-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f572e2574d0f865879218cbc40a018c4935bb4475c5a8a14b96fd3de21092c5a",
"md5": "ea8d82a03cb9fdbbba0f7a5961f3816f",
"sha256": "8091ff5f6e3f0bef8f8c847a95d784366762bc4426616c02381a071228b9b7fb"
},
"downloads": -1,
"filename": "npstructures-0.2.19.tar.gz",
"has_sig": false,
"md5_digest": "ea8d82a03cb9fdbbba0f7a5961f3816f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 47363,
"upload_time": "2024-05-31T08:54:06",
"upload_time_iso_8601": "2024-05-31T08:54:06.143458Z",
"url": "https://files.pythonhosted.org/packages/f5/72/e2574d0f865879218cbc40a018c4935bb4475c5a8a14b96fd3de21092c5a/npstructures-0.2.19.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-31 08:54:06",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "knutdrand",
"github_project": "npstructures",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "npstructures"
}