cf.CellMeasure.datum

CellMeasure.datum(*index)[source]

Return an element of the data array as a standard Python scalar.

The first and last elements are always returned with f.datum(0) and f.datum(-1) respectively, even if the data array is a scalar array or has two or more dimensions.

Parameters:
index : optional

Specify which element to return. When no positional arguments are provided, the method only works for data arrays with one element (but any number of dimensions), and the single element is returned. If positional arguments are given then they must be one of the following:

  • An integer. This argument is interpreted as a flat index into the array, specifying which element to copy and return.

    Example: If the data aray shape is (2, 3, 6) then:
    • f.datum(0) is equivalent to f.datum(0, 0, 0).
    • f.datum(-1) is equivalent to f.datum(1, 2, 5).
    • f.datum(16) is equivalent to f.datum(0, 2, 4).

    If index is 0 or -1 then the first or last data array element respecitively will be returned, even if the data array is a scalar array or has two or more dimensions.

  • Two or more integers. These arguments are interpreted as a multidimensionsal index to the array. There must be the same number of integers as data array dimensions.
  • A tuple of integers. This argument is interpreted as a multidimensionsal index to the array. There must be the same number of integers as data array dimensions.

    Example: f.datum((0, 2, 4)) is equivalent to f.datum(0, 2, 4); and f.datum(()) is equivalent to f.datum().

Returns:
out :

A copy of the specified element of the array as a suitable Python scalar.

Examples:
>>> print f.array
2
>>> f.datum()
2
>>> 2 == f.datum(0) == f.datum(-1) == f.datum(())
True
>>> print f.array
[[2]]
>>> 2 == f.datum() == f.datum(0) == f.datum(-1)
True
>>> 2 == f.datum(0, 0) == f.datum((-1, -1)) == f.datum(-1, 0)
True
>>> print f.array
[[4 -- 6]
 [1 2 3]]
>>> f.datum(0)
4
>>> f.datum(-1)
3
>>> f.datum(1)
masked
>>> f.datum(4)
2
>>> f.datum(-2)
2
>>> f.datum(0, 0)
4
>>> f.datum(-2, -1)
6
>>> f.datum(1, 2)
3
>>> f.datum((0, 2))
6

Previous topic

cf.CellMeasure.cos

Next topic

cf.CellMeasure.delprop

This Page