MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / std

Function std

monai/transforms/utils_pytorch_numpy_unification.py:550–569  ·  view source on GitHub ↗

`torch.std` with equivalent implementation for numpy Args: x: array/tensor. Returns: the standard deviation of x.

(x: NdarrayTensor, dim: int | tuple | None = None, unbiased: bool = False)

Source from the content-addressed store, hash-verified

548
549
550def std(x: NdarrayTensor, dim: int | tuple | None = None, unbiased: bool = False) -> NdarrayTensor:
551 """`torch.std` with equivalent implementation for numpy
552
553 Args:
554 x: array/tensor.
555
556 Returns:
557 the standard deviation of x.
558 """
559
560 ret: NdarrayTensor
561 if dim is None:
562 ret = np.std(x) if isinstance(x, (np.ndarray, list)) else torch.std(x, unbiased) # type: ignore
563 else:
564 if isinstance(x, (np.ndarray, list)):
565 ret = np.std(x, axis=dim)
566 else:
567 ret = torch.std(x, int(dim), unbiased) # type: ignore
568
569 return ret
570
571
572def sum(x: NdarrayTensor, dim: int | tuple | None = None, **kwargs) -> NdarrayTensor:

Callers 1

_stdshiftMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected