Structure#
- class Structure[source]#
Bases:
object
Simple structure class that can hold any type of data. Structure is constructed when calling __setitem__ and can grow in complexity.
Example:
s = Structure() s['_x', 'C_a'] = {'C_a_0':[1,2,3], 'C_a_1': [2,3,4]} s['_x', 'C_b'] = 'C_b' s['_u', 'C_a'] = 'C_a'
investigate the indices with
s.powerindex
. This yield the following:[('_x', 'C_a', 'C_a_0', 0), ('_x', 'C_a', 'C_a_0', 1), ('_x', 'C_a', 'C_a_0', 2), ('_x', 'C_a', 'C_a_1', 0), ('_x', 'C_a', 'C_a_1', 1), ('_x', 'C_a', 'C_a_1', 2), ('_x', 'C_b'), ('_u', 'C_a'), ('_x', 'C_a', 'C_a_0', 0), ('_x', 'C_a', 'C_a_0', 1), ('_x', 'C_a', 'C_a_0', 2), ('_x', 'C_a', 'C_a_1'), ('_x', 'C_b'), ('_u', 'C_a')]
Query the structure as follows:
s['_x', 'C_a'] >> [1, 2, 3, 2, 3, 4] s['_x', 'C_b'] >> [C_b]
Slicing is supported:
s['_x', 'C_a', :, 1:] >> [[[2], [3]], [[3], [4]]]
and introduces nested lists for each slice element.
Methods#
Attributes#
full#
- Structure.full#
Return all elements of the structure. Elements are returned in an unnested list.
get_index#
- Structure.get_index#
Get regular indices ([0,1,2, … N]) for the queried elements. This call mimics the __getitem__ method but returns the indices of the queried elements instead of their values.
This is an IndexedProperty and can thus be queried as shown below:
Example:
# Sample structure: s = Structure() s['_x', 'C_a'] = {'C_a_0':[1,2,3], 'C_a_1': [2,3,4]} s['_x', 'C_b'] = 'C_b' s['_u', 'C_a'] = 'C_a' # Get indices: s.get_index['_x', 'C_a'] s.get_index['_x', 'C_a', :, 1:]
The same nested list structure is obtained when using slices.