cf.Field.__getitem__¶
-
Field.
__getitem__
(indices)[source]¶ Return a subspace of the field construct defined by indices.
f.__getitem__(indices) <==> f[indices]
Subspacing by indexing uses rules that are very similar to the numpy indexing rules, the only differences being:
An integer index i specified for a dimension reduces the size of this dimension to unity, taking just the i-th element, but keeps the dimension itself, so that the rank of the array is not reduced.
When two or more dimensions’ indices are sequences of integers then these indices work independently along each dimension (similar to the way vector subscripts work in Fortran). This is the same indexing behaviour as on a Variable object of the netCDF4 package.
For a dimension that is cyclic, a range of indices specified by a
slice
that spans the edges of the data (such as-2:3
or3:-2:-1
) is assumed to “wrap” around, rather then producing a null result.
Examples:
>>> f.shape (12, 73, 96) >>> f[0].shape (1, 73, 96) >>> f[3, slice(10, 0, -2), 95:93:-1].shape (1, 5, 2)
>>> f.shape (12, 73, 96) >>> f[:, [0, 72], [5, 4, 3]].shape (12, 2, 3)
>>> f.shape (12, 73, 96) >>> f[...].shape (12, 73, 96) >>> f[slice(0, 12), :, 10:0:-2].shape (12, 73, 5) >>> f[[True, True, False, True, True, False, False, True, True, True, ... True, True]].shape (9, 64, 128) >>> f[..., :6, 9:1:-2, [1, 3, 4]].shape (6, 4, 3)