cf.Data.sqrt¶
-
Data.
sqrt
(dtype=None, inplace=False)[source]¶ Calculate the non-negative square root.
New in version 3.14.0.
See also
- Parameters
- dtype: data-type, optional
Overrides the data type of the output arrays. A matching precision of the calculation should be chosen. For example, a dtype of ``’int32’` is not allowed, even if the input values are perfect squares.
- Returns
Examples
>>> d = cf.Data([[0, 1, 2, 3, 4]], 'K2', mask=[[0, 0, 0, 1, 0]]) >>>print(d.array) [[0 1 2 -- 4]] >>> e = d.sqrt() >>> e <CF Data(1, 5): [[0.0, ..., 2.0]] K> >>> print(e.array) [[0.0 1.0 1.4142135623730951 -- 2.0]]
Negative input values raise a warning but nonetheless result in NaN or, if there are already missing values, missing data:
>>> import warnings >>> d = cf.Data([0, 1, -4]) >>> print(d.array) [ 0 1 -4] >>> with warnings.catch_warnings(): ... warnings.simplefilter("ignore") ... print(d.sqrt().array) ... [ 0. 1. nan]
>>> d = cf.Data([0, 1, -4], mask=[1, 0, 0]) >>> print(d.array) [-- 1 -4] >>> with warnings.catch_warnings(): ... warnings.simplefilter("ignore") ... print(d.sqrt().array) ... [-- 1.0 --]