File: loom_layer.rst

package info (click to toggle)
python-loompy 3.0.7%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,316 kB
  • sloc: python: 3,152; sh: 63; makefile: 16
file content (40 lines) | stat: -rw-r--r-- 1,215 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
LoomLayer (class)
=================

A LoomLayer represents a layer of data and provides a numpy ndarray-like interface.

.. highlight:: python
.. code-block:: python

    with loompy.connect("mydataset.loom") as ds:
        # Names of all the layers ("" is the main matrix)
        ds.layers.keys()

        # Upper left corner of the main matrix
        ds.layers[""][0,0]  
        
        # Shorthand to slice the main matrix
        ds[0,0]

        # Load the entire layer named "spliced"
        ds.layers["spliced"][:, :]

        # Shorthand access to the layer named "spliced"
        ds["spliced"][:, :]

        # Assign a row of data to the named layer
        ds["spliced"][0, :] = new_data

        # Create a new empty layer of `ìnt32`` elements
        ds["empty_layer"] = "int32"

Layers can also be accessed using numpy fancy indexing, e.g. with a vector of bools or a list of element indices. 

.. tip::
    Note that 
    using fancy indexing to slice more than ~1% of the rows (or columns) is inefficient. If you want to extract a larger subset 
    of rows or columns, you're better of using :meth:`.LoomConnection.scan`.

.. autoclass:: loompy.LoomLayer
    :members: 
    :undoc-members: