Bases: cf.utils.CfList
An N-dimensional partition array.
Initialization
Parameters : |
|
---|
# _FillValue : optional # The fill value of the data array. By default the numpy fill # value appropriate to the data-type will be used.
- direction : bool or dict, optional
- The direction of each dimension of the data array. It is a boolean if the data array is a scalar array, otherwise it is a dictionary keyed by the dimensions’ identities found in order.
# ndim : int, optional # Number of dimensions in the data array.
- order : list, optional
- The identities of the dimensions of the data array. If the data array is a scalar array then it is an empty list.
- pdims : list, optional
- The identities of the partition dimensions of the partition array. Each element is also found in order. If partition array is a scalar array then it is an empty list.
# shape : list, optional # The data array’s dimension sizes. # # size : int, optional # Number of elements in the data array. # # Units : Units, optional # The units of the data.
Examples
>>> pa = PartitionArray(
[Partition(location = [(0,n) for n in shape],
shape = shape[:],
order = order[:],
direction = copy(direction),
Units = units.copy(),
part = [],
data = data)
],
order = order,
# hardmask = False,
# shape = shape,
# size = data.size,
# Units = units.copy(),
# ndim = ndim,
direction = direction,
pdims = [],
_FillValue = _FillValue)
PartitionArray attributes
isscalar | True if the master array is a 0-d scalar array. |
pndim | The number of partition dimensions in the partition array. |
pshape | Examples |
psize | The number of partitions in the partition array. |
PartitionArray methods (undocumented methods behave exactly as their counterparts in a built-in list)
add_partitions | |
append | |
change_dimension_names | dim_name_map should be a dictionary which maps each dimension names in |
copy | Return a deep copy. |
count | Return the number of occurrences of a given value. |
equals | True if two instances are equal, False otherwise. |
expand_pdims | Insert a new size 1 partition dimension in place. |
extend | |
flat | Return a flat iterator over the Partition objects in the partition |
index | Return the first index of a given value. |
info | |
insert | Insert an object before the given index in place. |
partition_boundaries | |
pop | |
ravel | Return a flattened partition array as a built-in list. |
remove | |
reverse | |
rollaxis | Roll the specified partition dimension backwards,in place until it lies in a given position. |
set_location_map | Recalculate the location attribute of each Partition object in the |
squeeze | Remove all size 1 partition dimensions in place. |
transpose | Permute the partition dimensions of the partition array in place. |
dim_name_map should be a dictionary which maps each dimension names in self.order to its new dimension name. E.g. {‘dim0’:’dim1’, ‘dim1’:’dim0’}
Return a deep copy.
Do not set the _copy_attr parameter. It is for internal use only.
Equivalent to copy.deepcopy(pa).
Returns : |
|
---|
Examples
>>> pa.copy()
Return the number of occurrences of a given value.
Uses numerically tolerant equality where appropriate.
Parameters : |
|
---|---|
Returns : |
|
Examples
>>> s
[1, 2, 3, 2, 4, 2]
>>> s.count(1)
1
>>> s.count(2)
3
True if two instances are equal, False otherwise.
Two instances are equal if their attributes are equal and their elements are equal pair-wise.
Parameters : |
|
---|---|
Returns : |
|
Insert a new size 1 partition dimension in place.
The new parition dimension is inserted at position 0.
Parameters : |
|
---|---|
Returns : | None |
Examples
>>> pa.pdims
['dim0', 'dim1']
>>> pa.expand_pdims('dim2')
>>> pa.pdims
['dim2', 'dim0', 'dim1']
Return a flat iterator over the Partition objects in the partition array.
Returns : |
|
---|
Examples
>>> type(pa.flat())
<generator object flat at 0x145a0f0>
>>> for partition in pa.flat():
... print partition.Units
Return the first index of a given value.
Uses numerically tolerant equality where appropriate.
Parameters : |
|
---|---|
Returns : | out : int |
Raises : |
|
Examples
>>> s
[1, 2, 3, 2, 4, 2]
>>> s.index(1)
1
>>> s.index(2, 2)
3
>>> s.index(2, start=2, stop=5)
3
>>> s.index(6)
ValueError: CfList doesn't contain: 6
Insert an object before the given index in place.
Parameters : | index : int item : |
---|---|
Returns : | None |
Examples
>>> s
[1, 2, 3]
>>> s.insert(1, 'A')
>>> s
[1, 'A', 2, 3]
>>> s.insert(100, 'B')
[1, 'A', 2, 3, 'B']
>>> s.insert(100, 'B')
[1, 'A', 2, 3, 'B']
>>> s.insert(-2, 'C')
[1, 'A', 2, 'C', 3, 'B']
>>> s.insert(-100, 'D')
['D', 1, 'A', 2, 'C', 3, 'B']
Return a flattened partition array as a built-in list.
Returns : |
|
---|
Examples
>>> x = partitions.ravel()
>>> type(x)
list
Roll the specified partition dimension backwards,in place until it lies in a given position.
This does not change the master array.
Parameters : |
|
---|---|
Returns : | None |
Examples
>>> pa.rollaxis(2)
>>> pa.rollaxis(2, start=1)
Recalculate the location attribute of each Partition object in the partition array in place.
Examples
>>> pa.set_location_map()
Remove all size 1 partition dimensions in place.
Returns : | None |
---|
Examples
>>> pa.pdims
['dim0', 'dim1', 'dim2']
>>> pa._list
[[[<cf.partition.Partition object at 0x145daa0>,
<cf.partition.Partition object at 0x145db90>]],
[[<cf.partition.Partition object at 0x145dc08>,
<cf.partition.Partition object at 0x145dd70>]]]
>>> pa.squeeze()
>>> pa.pdims
['dim0', 'dim2']
>>> pa._list
[[<cf.partition.Partition object at 0x145daa0>,
<cf.partition.Partition object at 0x145db90>],
[<cf.partition.Partition object at 0x145dc08>,
<cf.partition.Partition object at 0x145dd70>]]
Permute the partition dimensions of the partition array in place.
This does not change the master array.
Parameters : |
|
---|---|
Returns : | None |
Examples
>>> pa.transpose((2,0,1))
True if the master array is a 0-d scalar array.
Examples
>>> pa.order
[]
>>> pa.isscalar
True
>>> len(pa.order) >= 1
True
>>> pa.isscalar
False
The number of partition dimensions in the partition array.
Examples
>>> pa.pndim
2
Examples
The number of partitions in the partition array.
Examples
>>> pa.psize
7