`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)
| 548 | |
| 549 | |
| 550 | def 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 | |
| 572 | def sum(x: NdarrayTensor, dim: int | tuple | None = None, **kwargs) -> NdarrayTensor: |