tiledbsoma.Collection.add_new_sparse_ndarray

Collection.add_new_sparse_ndarray(key: str, *, cls: Type[_NDArr], uri: str | None = None, type: pa.DataType, shape: Sequence[int | None], platform_config: options.PlatformConfig | None = None) SparseNDArray

Adds a new SparseNDArray to this Collection.

For details about the behavior of key and uri, see add_new_collection(). The remaining parameters are passed to the SparseNDArray.create() method unchanged.

Examples

>>> with tiledbsoma.Collection.create("./test_collection") as my_collection:
...     a_sparse_ndarray = my_collection.add_new_sparse_ndarray(
...         "a_sparse_ndarray", type=pa.float32(), shape=(100, 100)
...     )
...     data = pa.SparseCOOTensor.from_scipy(
...         scipy.sparse.random(100, 100, dtype=np.float32)
...     )
...     a_sparse_ndarray.write(data)
...
>>> with tiledbsoma.open("./test_collection") as my_collection:
...     data = my_collection["a_sparse_ndarray"].read().coos().concat()
...
>>> data
<pyarrow.SparseCOOTensor>
type: float
shape: (100, 100)
>>> data.to_scipy()
<100x100 sparse matrix of type '<class 'numpy.float32'>'
        with 100 stored elements in COOrdinate format>

Lifecycle

Maturing.