Performs Lp normalization of the tensor along the specified dimension. See: https://pytorch.org/docs/stable/generated/torch.nn.functional.normalize.html ```python exec="true" source="above" session="tensor" result="python" Tensor.manual_seed(42) t = Tensor.randn(2, 3) prin
(self, p:float=2.0, dim:int=1, eps:float=1e-12)
| 521 | return self.std(axis, keepdim, correction), self.mean(axis, keepdim) |
| 522 | |
| 523 | def normalize(self, p:float=2.0, dim:int=1, eps:float=1e-12) -> Self: |
| 524 | """ |
| 525 | Performs Lp normalization of the tensor along the specified dimension. |
| 526 | |
| 527 | See: https://pytorch.org/docs/stable/generated/torch.nn.functional.normalize.html |
| 528 | |
| 529 | ```python exec="true" source="above" session="tensor" result="python" |
| 530 | Tensor.manual_seed(42) |
| 531 | t = Tensor.randn(2, 3) |
| 532 | print(t.numpy()) |
| 533 | ``` |
| 534 | ```python exec="true" source="above" session="tensor" result="python" |
| 535 | print(t.normalize().numpy()) |
| 536 | ``` |
| 537 | ```python exec="true" source="above" session="tensor" result="python" |
| 538 | print(t.normalize(p=1, dim=0).numpy()) |
| 539 | ``` |
| 540 | """ |
| 541 | if p == 0: return self / self.ne(0).sum(dim, keepdim=True).maximum(eps) |
| 542 | return self / self.abs().pow(p).sum(dim, keepdim=True).pow(1/p).maximum(eps) |
| 543 | |
| 544 | def logsumexp(self, axis=None, keepdim=False) -> Self: |
| 545 | """ |
no test coverage detected