cfdm.Data.__setitem__

Data.__setitem__(indices, value)[source]

Assign to data elements defined by indices.

d.__setitem__(indices, x) <==> d[indices]=x

Indexing follows rules that are very similar to the numpy indexing rules, the only differences being:

  • An integer index i takes the i-th element but does not reduce the rank by one.

  • 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 behaviour as indexing on a Variable object of the netCDF4 package.

Broadcasting

The value, or values, being assigned must be broadcastable to the shape defined by the indices, using the numpy broadcasting rules.

Missing data

Data array elements may be set to missing values by assigning them to masked. Missing values may be unmasked by assigning them to any other value.

New in version (cfdm): 1.7.0

See also

__getitem__, _parse_indices

Returns

None

Examples:

>>> d = cfdm.Data(numpy.arange(100, 190).reshape(1, 10, 9))
>>> d.shape
(1, 10, 9)
>>> d[:, :, 1] = -10
>>> d[:, 0] = range(9)
>>> d[..., 6:3:-1, 3:6] = numpy.arange(-18, -9).reshape(3, 3)
>>> d[0, [2, 9], [4, 8]] = cfdm.Data([[-2, -3]])
>>> d[0, :, -2] = cfdm.masked