Skip to main content

Save and load matrices in the dolomite framework

Project description

Project generated with PyScaffold PyPI-Server Monthly Downloads Unit tests

Read and save matrices in Python

Introduction

The dolomite-matrix package is the Python counterpart to the alabaster.matrix R package, providing methods for saving/reading arrays and matrices within the dolomite framework. Dense arrays are stored in the usual HDF5 dataset, while sparse matrices are saved inside a HDF5 file in compressed sparse format.

Quick start

Let's save a dense matrix to a HDF5 file with some accompanying metadata:

import numpy
x = numpy.random.rand(1000, 200) 

import os
import tempfile
dir = os.path.join(tempfile.mkdtemp(), "whee")

import dolomite_base
import dolomite_matrix
dolomite_base.save_object(x, dir)

Now we can transfer the directory and reload the matrix in a new session. This constructs a HDF5-backed dense array that can be used for block processing or realized into the usual NumPy array.

import dolomite_base
obj = dolomite_base.read_object(dir)
## <1000 x 200> ReloadedArray object of type 'float64'
## [[0.58444226, 0.82595149, 0.7214525 , ..., 0.32493652, 0.58206044,
##   0.73770346],
##  [0.96398317, 0.73200292, 0.16410134, ..., 0.31626547, 0.11499628,
##   0.19768697],
##  [0.82350911, 0.48012452, 0.65221052, ..., 0.94989611, 0.15422992,
##   0.77173718],
##  ...,
##  [0.71715436, 0.19266116, 0.52316388, ..., 0.23104537, 0.935654  ,
##   0.51663007],
##  [0.38585049, 0.26709808, 0.70358993, ..., 0.91822795, 0.66144925,
##   0.42465112],
##  [0.08535589, 0.00144712, 0.51411921, ..., 0.84546122, 0.35001404,
##   0.53644868]]

Sparse matrices

We can also save and load a sparse matrix from a HDF5 file:

import scipy 
import numpy
x = scipy.sparse.random(1000, 200, 0.2, dtype=numpy.int16, format="csc")

import os
import tempfile
dir = os.path.join(tempfile.mkdtemp(), "stuff")

import dolomite_base
import dolomite_matrix
dolomite_base.save_object(x, dir)

And again, loading it back in a new session. This constructs a HDF5-backed sparse array that can be used for block processing or realized into the usual NumPy array.

import dolomite_base
obj = dolomite_base.read_object(dir)
## <1000 x 200> sparse ReloadedArray object of type 'int16'
## [[     0,      0, -28638, ...,      0,      0,  26194],
##  [     0,      0,      0, ...,      0, -30829,      0],
##  [     0,      0,      0, ...,      0,      0,      0],
##  ...,
##  [ 10895,      0,      0, ...,      0,      0,      0],
##  [     0,  32539,      0, ...,      0,   2780, -12106],
##  [     0,      0,      0, ...,   1452,      0, -26314]]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dolomite_matrix-0.3.0.tar.gz (39.1 kB view details)

Uploaded Source

Built Distribution

dolomite_matrix-0.3.0-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file dolomite_matrix-0.3.0.tar.gz.

File metadata

  • Download URL: dolomite_matrix-0.3.0.tar.gz
  • Upload date:
  • Size: 39.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for dolomite_matrix-0.3.0.tar.gz
Algorithm Hash digest
SHA256 ede7f8ed345eedc9ad41130af55f52cd816109ceb81ea038bda1217ff9122bd7
MD5 422401c2f2ce5a18e3b933a0df2d3e4c
BLAKE2b-256 1368ba5bf793f72033d132a824de4358924bc264fb1e3ce49916a19ec6701a73

See more details on using hashes here.

File details

Details for the file dolomite_matrix-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for dolomite_matrix-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 94bc370d6d44e540f27a17b98a1d655f8a55f5a92f503e42de9a91d7ffecc5ad
MD5 7028eb3657b0fa2dc8a16b6e5e879e92
BLAKE2b-256 11a7c5cbb0a1de0e044716c5425f34b1e3e6073319dff22c7e4571218e4c5321

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page