h5sparse


Nameh5sparse JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/appier/h5sparse
SummaryScipy sparse matrix in HDF5.
upload_time2019-02-24 12:27:14
maintainer
docs_urlNone
authorAppier Inc.
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements six h5py numpy scipy pylint tox flake8 nose coverage
Travis-CI
coveralls test coverage No coveralls.
            Please visit  the `Github repository <https://github.com/appier/h5sparse>`_
for more information.

h5sparse
========
.. image:: https://img.shields.io/travis/appier/h5sparse/master.svg
   :target: https://travis-ci.org/appier/h5sparse
.. image:: https://img.shields.io/pypi/v/h5sparse.svg
   :target: https://pypi.python.org/pypi/h5sparse
.. image:: https://img.shields.io/pypi/l/h5sparse.svg
   :target: https://pypi.python.org/pypi/h5sparse

Scipy sparse matrix in HDF5.


Installation
------------
.. code:: bash

   pip install h5sparse


Testing
-------
- for single environment:

  .. code:: bash

     python setup.py test

- for all environments:

  .. code:: bash

     tox


Examples
--------

Create dataset
**************
.. code:: python

   In [1]: import scipy.sparse as ss
      ...: import h5sparse
      ...: import numpy as np
      ...:

   In [2]: sparse_matrix = ss.csr_matrix([[0, 1, 0],
      ...:                                [0, 0, 1],
      ...:                                [0, 0, 0],
      ...:                                [1, 1, 0]],
      ...:                               dtype=np.float64)

   In [3]: # create dataset from scipy sparse matrix
      ...: with h5sparse.File("test.h5") as h5f:
      ...:     h5f.create_dataset('sparse/matrix', data=sparse_matrix)

   In [4]: # you can also create dataset from another dataset
      ...: with h5sparse.File("test.h5") as h5f:
      ...:     h5f.create_dataset('sparse/matrix2', data=h5f['sparse/matrix'])

   In [5]: # you can also create dataset using the formats that original h5py accepts
      ...: with h5sparse.File("test.h5") as h5f:
      ...:     h5f.create_dataset('sparse/matrix3', data=[1,2,3])

Read dataset
************
.. code:: python

   In [6]: h5f = h5sparse.File("test.h5")

   In [7]: h5f['sparse/matrix'][1:3]
   Out[7]:
   <2x3 sparse matrix of type '<class 'numpy.float64'>'
           with 1 stored elements in Compressed Sparse Row format>

   In [8]: h5f['sparse/matrix'][1:3].toarray()
   Out[8]:
   array([[ 0.,  0.,  1.],
          [ 0.,  0.,  0.]])

   In [9]: h5f['sparse']['matrix'][1:3].toarray()
   Out[9]:
   array([[ 0.,  0.,  1.],
          [ 0.,  0.,  0.]])

   In [10]: h5f['sparse']['matrix'][2:].toarray()
   Out[10]:
   array([[ 0.,  0.,  0.],
          [ 1.,  1.,  0.]])

   In [11]: h5f['sparse']['matrix'][:2].toarray()
   Out[11]:
   array([[ 0.,  1.,  0.],
          [ 0.,  0.,  1.]])

   In [12]: h5f['sparse']['matrix'][-2:].toarray()
   Out[12]:
   array([[ 0.,  0.,  0.],
          [ 1.,  1.,  0.]])

   In [13]: h5f['sparse']['matrix'][:-2].toarray()
   Out[13]:
   array([[ 0.,  1.,  0.],
          [ 0.,  0.,  1.]])

   In [14]: h5f['sparse']['matrix'][()].toarray()
   Out[14]:
   array([[ 0.,  1.,  0.],
          [ 0.,  0.,  1.],
          [ 0.,  0.,  0.],
          [ 1.,  1.,  0.]])

   In [15]: import h5py

   In [16]: h5py_h5f = h5py.File("test.h5")

   In [17]: h5sparse.Group(h5py_h5f.id)['sparse/matrix'][()]
   Out[17]:
   <4x3 sparse matrix of type '<class 'numpy.float64'>'
           with 4 stored elements in Compressed Sparse Row format>

   In [18]: h5sparse.Group(h5py_h5f['sparse'].id)['matrix'][()]
   Out[18]:
   <4x3 sparse matrix of type '<class 'numpy.float64'>'
           with 4 stored elements in Compressed Sparse Row format>

   In [19]: h5sparse.Dataset(h5py_h5f['sparse/matrix'])[()]
   Out[19]:
   <4x3 sparse matrix of type '<class 'numpy.float64'>'
           with 4 stored elements in Compressed Sparse Row format>

Append dataset
**************
.. code:: python

   In [20]: to_append = ss.csr_matrix([[0, 1, 1],
       ...:                            [1, 0, 0]],
       ...:                           dtype=np.float64)

   In [21]: h5f.create_dataset('matrix', data=sparse_matrix, chunks=(100000,),
       ...:                    maxshape=(None,))

   In [22]: h5f['matrix'].append(to_append)

   In [23]: h5f['matrix'][()]
   Out[23]:
   <6x3 sparse matrix of type '<class 'numpy.float64'>'
           with 7 stored elements in Compressed Sparse Row format>

   In [24]: h5f['matrix'][()].toarray()
   Out[24]:
   array([[ 0.,  1.,  0.],
          [ 0.,  0.,  1.],
          [ 0.,  0.,  0.],
          [ 1.,  1.,  0.],
          [ 0.,  1.,  1.],
          [ 1.,  0.,  0.]])



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/appier/h5sparse",
    "name": "h5sparse",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Appier Inc.",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/a4/5c/f4b3d34076bbfe863d36fa1c503a95b19a72caf2de23bff3c4ad770a5297/h5sparse-0.1.0.tar.gz",
    "platform": "",
    "description": "Please visit  the `Github repository <https://github.com/appier/h5sparse>`_\nfor more information.\n\nh5sparse\n========\n.. image:: https://img.shields.io/travis/appier/h5sparse/master.svg\n   :target: https://travis-ci.org/appier/h5sparse\n.. image:: https://img.shields.io/pypi/v/h5sparse.svg\n   :target: https://pypi.python.org/pypi/h5sparse\n.. image:: https://img.shields.io/pypi/l/h5sparse.svg\n   :target: https://pypi.python.org/pypi/h5sparse\n\nScipy sparse matrix in HDF5.\n\n\nInstallation\n------------\n.. code:: bash\n\n   pip install h5sparse\n\n\nTesting\n-------\n- for single environment:\n\n  .. code:: bash\n\n     python setup.py test\n\n- for all environments:\n\n  .. code:: bash\n\n     tox\n\n\nExamples\n--------\n\nCreate dataset\n**************\n.. code:: python\n\n   In [1]: import scipy.sparse as ss\n      ...: import h5sparse\n      ...: import numpy as np\n      ...:\n\n   In [2]: sparse_matrix = ss.csr_matrix([[0, 1, 0],\n      ...:                                [0, 0, 1],\n      ...:                                [0, 0, 0],\n      ...:                                [1, 1, 0]],\n      ...:                               dtype=np.float64)\n\n   In [3]: # create dataset from scipy sparse matrix\n      ...: with h5sparse.File(\"test.h5\") as h5f:\n      ...:     h5f.create_dataset('sparse/matrix', data=sparse_matrix)\n\n   In [4]: # you can also create dataset from another dataset\n      ...: with h5sparse.File(\"test.h5\") as h5f:\n      ...:     h5f.create_dataset('sparse/matrix2', data=h5f['sparse/matrix'])\n\n   In [5]: # you can also create dataset using the formats that original h5py accepts\n      ...: with h5sparse.File(\"test.h5\") as h5f:\n      ...:     h5f.create_dataset('sparse/matrix3', data=[1,2,3])\n\nRead dataset\n************\n.. code:: python\n\n   In [6]: h5f = h5sparse.File(\"test.h5\")\n\n   In [7]: h5f['sparse/matrix'][1:3]\n   Out[7]:\n   <2x3 sparse matrix of type '<class 'numpy.float64'>'\n           with 1 stored elements in Compressed Sparse Row format>\n\n   In [8]: h5f['sparse/matrix'][1:3].toarray()\n   Out[8]:\n   array([[ 0.,  0.,  1.],\n          [ 0.,  0.,  0.]])\n\n   In [9]: h5f['sparse']['matrix'][1:3].toarray()\n   Out[9]:\n   array([[ 0.,  0.,  1.],\n          [ 0.,  0.,  0.]])\n\n   In [10]: h5f['sparse']['matrix'][2:].toarray()\n   Out[10]:\n   array([[ 0.,  0.,  0.],\n          [ 1.,  1.,  0.]])\n\n   In [11]: h5f['sparse']['matrix'][:2].toarray()\n   Out[11]:\n   array([[ 0.,  1.,  0.],\n          [ 0.,  0.,  1.]])\n\n   In [12]: h5f['sparse']['matrix'][-2:].toarray()\n   Out[12]:\n   array([[ 0.,  0.,  0.],\n          [ 1.,  1.,  0.]])\n\n   In [13]: h5f['sparse']['matrix'][:-2].toarray()\n   Out[13]:\n   array([[ 0.,  1.,  0.],\n          [ 0.,  0.,  1.]])\n\n   In [14]: h5f['sparse']['matrix'][()].toarray()\n   Out[14]:\n   array([[ 0.,  1.,  0.],\n          [ 0.,  0.,  1.],\n          [ 0.,  0.,  0.],\n          [ 1.,  1.,  0.]])\n\n   In [15]: import h5py\n\n   In [16]: h5py_h5f = h5py.File(\"test.h5\")\n\n   In [17]: h5sparse.Group(h5py_h5f.id)['sparse/matrix'][()]\n   Out[17]:\n   <4x3 sparse matrix of type '<class 'numpy.float64'>'\n           with 4 stored elements in Compressed Sparse Row format>\n\n   In [18]: h5sparse.Group(h5py_h5f['sparse'].id)['matrix'][()]\n   Out[18]:\n   <4x3 sparse matrix of type '<class 'numpy.float64'>'\n           with 4 stored elements in Compressed Sparse Row format>\n\n   In [19]: h5sparse.Dataset(h5py_h5f['sparse/matrix'])[()]\n   Out[19]:\n   <4x3 sparse matrix of type '<class 'numpy.float64'>'\n           with 4 stored elements in Compressed Sparse Row format>\n\nAppend dataset\n**************\n.. code:: python\n\n   In [20]: to_append = ss.csr_matrix([[0, 1, 1],\n       ...:                            [1, 0, 0]],\n       ...:                           dtype=np.float64)\n\n   In [21]: h5f.create_dataset('matrix', data=sparse_matrix, chunks=(100000,),\n       ...:                    maxshape=(None,))\n\n   In [22]: h5f['matrix'].append(to_append)\n\n   In [23]: h5f['matrix'][()]\n   Out[23]:\n   <6x3 sparse matrix of type '<class 'numpy.float64'>'\n           with 7 stored elements in Compressed Sparse Row format>\n\n   In [24]: h5f['matrix'][()].toarray()\n   Out[24]:\n   array([[ 0.,  1.,  0.],\n          [ 0.,  0.,  1.],\n          [ 0.,  0.,  0.],\n          [ 1.,  1.,  0.],\n          [ 0.,  1.,  1.],\n          [ 1.,  0.,  0.]])\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Scipy sparse matrix in HDF5.",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/appier/h5sparse"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "40ee8be7e1ba3844dc45e99e648d22fe214c8391c9e26245942221fea72a7e30",
                "md5": "552d4561859332b7faa88cd185064a30",
                "sha256": "03595909c9fd4e895c4b3f12ca7a1e7f95a5cb3610f07d862d7f59612e0302fa"
            },
            "downloads": -1,
            "filename": "h5sparse-0.1.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "552d4561859332b7faa88cd185064a30",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 6118,
            "upload_time": "2019-02-24T12:27:12",
            "upload_time_iso_8601": "2019-02-24T12:27:12.679764Z",
            "url": "https://files.pythonhosted.org/packages/40/ee/8be7e1ba3844dc45e99e648d22fe214c8391c9e26245942221fea72a7e30/h5sparse-0.1.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a45cf4b3d34076bbfe863d36fa1c503a95b19a72caf2de23bff3c4ad770a5297",
                "md5": "aa9b945fadade9fde9952be2b462af6e",
                "sha256": "b7e6fbfa2f2f61adaa169a3a0a52bc6f2178f5daff8fa6d972a8dcaa7f3cc8f7"
            },
            "downloads": -1,
            "filename": "h5sparse-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "aa9b945fadade9fde9952be2b462af6e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5297,
            "upload_time": "2019-02-24T12:27:14",
            "upload_time_iso_8601": "2019-02-24T12:27:14.461352Z",
            "url": "https://files.pythonhosted.org/packages/a4/5c/f4b3d34076bbfe863d36fa1c503a95b19a72caf2de23bff3c4ad770a5297/h5sparse-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2019-02-24 12:27:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "appier",
    "github_project": "h5sparse",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "six",
            "specs": []
        },
        {
            "name": "h5py",
            "specs": []
        },
        {
            "name": "numpy",
            "specs": []
        },
        {
            "name": "scipy",
            "specs": []
        },
        {
            "name": "pylint",
            "specs": []
        },
        {
            "name": "tox",
            "specs": []
        },
        {
            "name": "flake8",
            "specs": []
        },
        {
            "name": "nose",
            "specs": []
        },
        {
            "name": "coverage",
            "specs": []
        }
    ],
    "tox": true,
    "lcname": "h5sparse"
}
        
Elapsed time: 0.10722s