Name | npdict JSON |
Version |
0.0.2
JSON |
| download |
home_page | None |
Summary | A Python dictionary wrapper for numpy arrays |
upload_time | 2025-07-12 19:40:20 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | MIT |
keywords |
dictionary
numpy
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
[](https://github.com/stephenhky/npdict/releases)
[](https://pypi.org/project/npdict/)
[](https://pypi.org/project/npdict/)
# `npdict`: Python Package for Dictionary Wrappers for Numpy Arrays
This Python package, `npdict`, aims at facilitating holding numerical
values in a Python dictionary, but at the same time retaining the
ultra-high performance supported by NumPy. It supports an object
which is a Python dictionary on the surface, but numpy behind the
back, facilitating fast assignment and retrieval of values
and fast computation of numpy arrays.
## Installation
To install, in your terminal, simply enter:
```
pip install npdict
```
## Quickstart
### Instantiation
Suppose you are doing a similarity dictionary between two sets of words.
And each of these sets have words:
```
document1 = ['president', 'computer', 'tree']
document2 = ['chairman', 'abacus', 'trees']
```
And you can build a dictionary like this:
```
import numpy as np
from npdict import NumpyNDArrayWrappedDict
similarity_dict = NumpyNDArrayWrappedDict([document1, document2])
```
An `npdict.NumpyNDArrayWrappedDict` instance is instantiated. It is
a Python dict:
```
isinstance(similarity_dict, dict) # which gives `True`
```
It has a matrix inside with default value 0.0 (and the initial default value can
be changed to other values when the instance is instantiated.)
```
similarity_dict.to_numpy()
```
giving
```
array([[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]])
```
### Value Assignments
Now you can assign values just like what you do to a Python dictionary:
```
similarity_dict['president', 'chairman'] = 0.9
similarity_dict['computer', 'abacus'] = 0.7
similarity_dict['tree', 'trees'] = 0.95
```
And it has changed the inside numpy array to be:
```
array([[0.9 , 0. , 0. ],
[0. , 0.7 , 0. ],
[0. , 0. , 0.95]])
```
### Generation of New Object from the Old One
If you want to create another dict using the same words, but
a manipulation of the original value, 25 percent discount
of the original one for example, you can do something like this:
```
new_similarity_dict = similarity_dict.generate_dict(similarity_dict.to_numpy()*0.75)
```
And you got a new dictionary with numpy array to be:
```
new_similarity_dict.to_numpy()
```
giving
```
array([[0.675 , 0. , 0. ],
[0. , 0.525 , 0. ],
[0. , 0. , 0.7125]])
```
This is a simple operation. But the design of this wrapped Python
dictionary is that you can perform any fast or optimized operation
on your numpy array (using numba or Cython, for examples),
while retaining the keywords as your dictionary.
### Retrieval of Values
At the same time, you can set new values just like above, or retrieve
values as if it is a Python dictionary:
```
similarity_dict['president', 'chairman']
```
### Conversion to a Python Dictionary
You can also convert this to an ordinary Python dictionary:
```
raw_similarity_dict = similarity_dict.to_dict()
```
### Instantiation from a Python Dictionary
And you can convert a Python dictionary of this type back to
`npdict.NumpyNDArrayWrappedDict` by (recommended)
```
new_similarity_dict_2 = NumpyNDArrayWrappedDict.from_dict_given_keywords([document1, document2], raw_similarity_dict)
```
Or you can even do this (not recommended):
```
new_similarity_dict_3 = NumpyNDArrayWrappedDict.from_dict(raw_similarity_dict)
```
It is not recommended because the order of the keys are not retained in this way.
Use it with caution.
Raw data
{
"_id": null,
"home_page": null,
"name": "npdict",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "dictionary, numpy",
"author": null,
"author_email": "Kwan Yuet Stephen Ho <stephenhky@yahoo.com.hk>",
"download_url": "https://files.pythonhosted.org/packages/93/3e/229348bb80d5d33c72fd98d8358a0b284c847846ea5fefa704c620a9448f/npdict-0.0.2.tar.gz",
"platform": null,
"description": "\n[](https://github.com/stephenhky/npdict/releases)\n[](https://pypi.org/project/npdict/)\n[](https://pypi.org/project/npdict/)\n\n# `npdict`: Python Package for Dictionary Wrappers for Numpy Arrays\n\nThis Python package, `npdict`, aims at facilitating holding numerical\nvalues in a Python dictionary, but at the same time retaining the\nultra-high performance supported by NumPy. It supports an object\nwhich is a Python dictionary on the surface, but numpy behind the\nback, facilitating fast assignment and retrieval of values\nand fast computation of numpy arrays.\n\n## Installation\n\nTo install, in your terminal, simply enter:\n\n```\npip install npdict\n```\n\n## Quickstart\n\n### Instantiation\n\nSuppose you are doing a similarity dictionary between two sets of words.\nAnd each of these sets have words:\n\n```\ndocument1 = ['president', 'computer', 'tree']\ndocument2 = ['chairman', 'abacus', 'trees']\n```\n\nAnd you can build a dictionary like this:\n\n```\nimport numpy as np\nfrom npdict import NumpyNDArrayWrappedDict\n\nsimilarity_dict = NumpyNDArrayWrappedDict([document1, document2])\n```\n\nAn `npdict.NumpyNDArrayWrappedDict` instance is instantiated. It is \na Python dict:\n\n```\nisinstance(similarity_dict, dict) # which gives `True`\n```\n\nIt has a matrix inside with default value 0.0 (and the initial default value can\nbe changed to other values when the instance is instantiated.)\n\n```\nsimilarity_dict.to_numpy()\n```\ngiving\n```\narray([[0., 0., 0.],\n [0., 0., 0.],\n [0., 0., 0.]])\n```\n\n### Value Assignments\n\nNow you can assign values just like what you do to a Python dictionary:\n\n```\nsimilarity_dict['president', 'chairman'] = 0.9\nsimilarity_dict['computer', 'abacus'] = 0.7\nsimilarity_dict['tree', 'trees'] = 0.95\n```\n\nAnd it has changed the inside numpy array to be:\n\n```\narray([[0.9 , 0. , 0. ],\n [0. , 0.7 , 0. ],\n [0. , 0. , 0.95]])\n```\n\n### Generation of New Object from the Old One\n\nIf you want to create another dict using the same words, but \na manipulation of the original value, 25 percent discount\nof the original one for example, you can do something like this:\n\n```\nnew_similarity_dict = similarity_dict.generate_dict(similarity_dict.to_numpy()*0.75)\n```\n\nAnd you got a new dictionary with numpy array to be:\n\n```\nnew_similarity_dict.to_numpy()\n```\ngiving\n```\narray([[0.675 , 0. , 0. ],\n [0. , 0.525 , 0. ],\n [0. , 0. , 0.7125]])\n```\n\nThis is a simple operation. But the design of this wrapped Python\ndictionary is that you can perform any fast or optimized operation\non your numpy array (using numba or Cython, for examples),\nwhile retaining the keywords as your dictionary.\n\n### Retrieval of Values\n\nAt the same time, you can set new values just like above, or retrieve\nvalues as if it is a Python dictionary:\n\n```\nsimilarity_dict['president', 'chairman']\n```\n\n### Conversion to a Python Dictionary\n\nYou can also convert this to an ordinary Python dictionary:\n\n```\nraw_similarity_dict = similarity_dict.to_dict()\n```\n\n### Instantiation from a Python Dictionary\n\nAnd you can convert a Python dictionary of this type back to \n`npdict.NumpyNDArrayWrappedDict` by (recommended)\n\n```\nnew_similarity_dict_2 = NumpyNDArrayWrappedDict.from_dict_given_keywords([document1, document2], raw_similarity_dict)\n```\n\nOr you can even do this (not recommended):\n\n```\nnew_similarity_dict_3 = NumpyNDArrayWrappedDict.from_dict(raw_similarity_dict)\n```\n\nIt is not recommended because the order of the keys are not retained in this way.\nUse it with caution.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Python dictionary wrapper for numpy arrays",
"version": "0.0.2",
"project_urls": {
"Issues": "https://github.com/stephenhky/npdict/issues",
"Repository": "https://github.com/stephenhky/npdict"
},
"split_keywords": [
"dictionary",
" numpy"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "00e4972d8671253cd3291c71c98b73db205cd4b7d14b1ebc70cb9f59a8d4da58",
"md5": "5fa58d2e6b691015ef2f148cf777c228",
"sha256": "e5b9b3edad83a425614700e8af1eaadb60daa76c518f8e4e1ff9283ac1bcbfd7"
},
"downloads": -1,
"filename": "npdict-0.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5fa58d2e6b691015ef2f148cf777c228",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 6784,
"upload_time": "2025-07-12T19:40:20",
"upload_time_iso_8601": "2025-07-12T19:40:20.041032Z",
"url": "https://files.pythonhosted.org/packages/00/e4/972d8671253cd3291c71c98b73db205cd4b7d14b1ebc70cb9f59a8d4da58/npdict-0.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "933e229348bb80d5d33c72fd98d8358a0b284c847846ea5fefa704c620a9448f",
"md5": "234fbd78a6919619a54d020653d92690",
"sha256": "f7cb533c0cebf3f14034caca59466bb832291ee1cce7b535472505cc2ee577ca"
},
"downloads": -1,
"filename": "npdict-0.0.2.tar.gz",
"has_sig": false,
"md5_digest": "234fbd78a6919619a54d020653d92690",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 10410,
"upload_time": "2025-07-12T19:40:20",
"upload_time_iso_8601": "2025-07-12T19:40:20.975241Z",
"url": "https://files.pythonhosted.org/packages/93/3e/229348bb80d5d33c72fd98d8358a0b284c847846ea5fefa704c620a9448f/npdict-0.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-12 19:40:20",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "stephenhky",
"github_project": "npdict",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "npdict"
}