dbarray
|
Array stored in database. More...
Public Member Functions | |
def | __init__ |
Initialize the `DBArray`. | |
def | __del__ |
Destroy the `DBArray`. | |
def | __len__ |
Get number of rows. | |
def | __getitem__ |
Get a subarray from DB. | |
def | __setitem__ |
Set a subarray in DB. | |
def | set_shape |
Set shape of `DBArray`. | |
def | set_dtype |
Set dtype of `DBArray`. | |
def | get_rows |
Get rows from DB. | |
def | set_rows |
Set rows of DB. | |
def | get_row |
Get a row. | |
def | set_row |
Set a row. | |
def | set_db_attr |
Set DB attribute. | |
def | get_db_attr |
Set DB attribute. | |
def | fromndarray |
Construct `DBArray` from `ndarray`. | |
def | tondarray |
Load data to `ndarray` from `DBArray`. | |
Public Attributes | |
nrows | |
Number of rows in the array. | |
ncols | |
Number of cols in the array. | |
dtype | |
Associated data-type describes the format of each element in the array, which is compact with `numpy`. |
Array stored in database.
`DBArray` is an 2D array stored in database. The purpose of this class is to provide a way to store and access large array which can not be loaded into memory.
An associated data-type object describes the format of each element in the array. (The data-type is compact with `numpy`)
def src.dbarray.DBArray.__init__ | ( | self, | |
dbpath, | |||
dbtype = DEFAULT_DTYPE |
|||
) |
Initialize the `DBArray`.
Args: `dbpath` [str] path of the database. `dbtype` [str] type of the database.
Returns: N/A
def src.dbarray.DBArray.__del__ | ( | self | ) |
Destroy the `DBArray`.
Args: N/A
Returns: N/A
def src.dbarray.DBArray.__getitem__ | ( | self, | |
key | |||
) |
Get a subarray from DB.
Args: `key` [str, integer, slice or tuple] An `key` of type `str` corresponds to an attribute. Other kinds of `key`s correspond to array indices.
Returns: `attr` [str, int or numpy.ndarray] for `key` of type `str`. `subarray` [numpy.ndarray] for `key` of other types.
def src.dbarray.DBArray.__setitem__ | ( | self, | |
key, | |||
val | |||
) |
Set a subarray in DB.
Args: `key` [str, integer, slice or tuple] An `key` of type `str` corresponds to an attribute. Other kinds of `key`s correspond to array indices. `val` [str, int or numpy.ndarray] for `key` of type `str`. [numpy.ndarray] for `key` of other types.
Returns: N/A
def src.dbarray.DBArray.fromndarray | ( | cls, | |
arr, | |||
dbpath, | |||
dbtype = DEFAULT_DTYPE |
|||
) |
Construct `DBArray` from `ndarray`.
Args: `arr` [numpy.ndarray] The source `ndarray`. `dbpath` [str] Path of the database. `dbtype` [str] Type of the database.
Returns: `dba` [DBArray]
def src.dbarray.DBArray.get_db_attr | ( | self, | |
key | |||
) |
Set DB attribute.
Args: `key` [str] Name of the attribute.
Returns: `val` [str, int or 1-row numpy.ndarray] Value of the attribute.
def src.dbarray.DBArray.get_row | ( | self, | |
rid | |||
) |
Get a row.
Args: `rid` [int] A single row Id.
Returns: `subarray` [numpy.ndarray] Row vector specified by `rid`.
def src.dbarray.DBArray.get_rows | ( | self, | |
v_rid | |||
) |
Get rows from DB.
Args: `v_rid` [list of int] A list of row Ids.
Returns: `subarray` [numpy.ndarray] rows specified by `v_rid`.
def src.dbarray.DBArray.set_db_attr | ( | self, | |
key, | |||
val | |||
) |
Set DB attribute.
Args: `key` [str] Name of the attribute. `val` [str, int or 1-row numpy.ndarray] Value of the attribute. The following attribute type are supported: 'nda': numpy.ndarray 'int': int 'str': string
Returns: N/A
def src.dbarray.DBArray.set_dtype | ( | self, | |
dtype | |||
) |
Set dtype of `DBArray`.
Args: `dtype` [str or numpy.dtype] Can be any valid numpy.dtype.
Returns: N/A
def src.dbarray.DBArray.set_row | ( | self, | |
rid, | |||
arr | |||
) |
Set a row.
Args: `rid` [int] A single row Id. `arr` [numpy.ndarray] Row vector specified by `rid`.
Returns: N/A
def src.dbarray.DBArray.set_rows | ( | self, | |
v_rid, | |||
arr | |||
) |
Set rows of DB.
Args: `v_rid` [list of int] A list of row Ids. `arr` [numpy.ndarray] Rows specified by `v_rid`.
Returns: N/A
def src.dbarray.DBArray.set_shape | ( | self, | |
shape | |||
) |
Set shape of `DBArray`.
Args: `shape` [tuple of int: (nrows, ncols)] Specify number of rows and cols of `DBArray`.
Returns: N/A
def src.dbarray.DBArray.tondarray | ( | self | ) |
Load data to `ndarray` from `DBArray`.
Args: N/A
Returns: `arr` [numpy.ndarray]