cfdm.Field.insert_dimension¶
-
Field.
insert_dimension
(axis, position=0, constructs=False, inplace=False)[source]¶ Expand the shape of the data array.
Inserts a new size 1 axis, corresponding to an existing domain axis construct, into the data array.
New in version (cfdm): 1.7.0
- Parameters
- axis:
str
The identifier of the domain axis construct corresponding to the inserted axis.
If axis is
None
then a new domain axis construct will be created for the inserted dimension.- Parameter example:
axis='domainaxis2'
- position:
int
, optional Specify the position that the new axis will have in the data array. By default the new axis has position 0, the slowest varying position. Negative integers counting from the last position are allowed.
- Parameter example:
position=2
- Parameter example:
position=-1
- constructs:
bool
If True then also insert the new axis into all metadata constructs that don’t already include it. By default, metadata constructs are not changed.
New in version (cfdm): 1.11.1.0
- inplace:
bool
, optional If True then do the operation in-place and return
None
.
- axis:
- Returns
Examples
>>> f.data.shape (19, 73, 96) >>> f.insert_dimension('domainaxis3').data.shape (1, 96, 73, 19) >>> f.insert_dimension('domainaxis3', position=3).data.shape (19, 73, 96, 1) >>> f.insert_dimension('domainaxis3', position=-1, inplace=True) (19, 73, 1, 96) >>> f.data.shape (19, 73, 1, 96) >>> f.insert_dimension(None, 1).data.shape (19, 1, 73, 1, 96)