From 78024e81f857420eb748656af6cdf00da997088a Mon Sep 17 00:00:00 2001 From: bh-official Date: Sun, 25 Oct 2026 22:52:30 +0000 Subject: [PATCH] docs: document axis and keepdims for Tensor.sum and Tensor.mean The API reference described both methods as a full reduction, not per-axis, but they accept axis (int, tuple or None, negatives allowed) and keepdims. Add a parameter table and shape examples for each. Closes #5 --- docs/api-reference/tensor.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/api-reference/tensor.md b/docs/api-reference/tensor.md index f4ad80b..e3c319c 100644 --- a/docs/api-reference/tensor.md +++ b/docs/api-reference/tensor.md @@ -74,10 +74,24 @@ Returns a new Tensor: `ln(x)` element-wise (natural logarithm). Note: `log(0)` returns `-inf`, `log(negative)` returns `nan`. ### `sum(axis=None, keepdims=False)` -Returns a new Tensor with the sum of all elements (full reduction, not per-axis). +Returns a new Tensor with the sum of the elements, reduced over all elements or over the given axis. + +| Parameter | Type | Default | Description | +|-----------|------|---------|-------------| +| `axis` | int, tuple of int, or None | `None` | Axis or axes to reduce. Negative axes are allowed. `None` reduces over all elements and returns a scalar (0-d) Tensor | +| `keepdims` | bool | `False` | If `True`, the reduced axes are kept with size 1 so the result broadcasts against the input | + +For an input of shape `(2, 3)`: `.sum()` has shape `()`, `.sum(axis=0)` has shape `(3,)`, `.sum(axis=1, keepdims=True)` has shape `(2, 1)`. ### `mean(axis=None, keepdims=False)` -Returns a new Tensor with the mean of all elements (full reduction, not per-axis). +Returns a new Tensor with the mean of the elements, reduced over all elements or over the given axis. + +| Parameter | Type | Default | Description | +|-----------|------|---------|-------------| +| `axis` | int, tuple of int, or None | `None` | Axis or axes to reduce. Negative axes are allowed. `None` reduces over all elements and returns a scalar (0-d) Tensor | +| `keepdims` | bool | `False` | If `True`, the reduced axes are kept with size 1 so the result broadcasts against the input | + +For an input of shape `(2, 3)`: `.mean()` has shape `()`, `.mean(axis=0)` has shape `(3,)`, `.mean(axis=1, keepdims=True)` has shape `(2, 1)`. ### `matmul(other)` Matrix multiplication equivalent to `self @ other`.