Skip to content

Commit bcfd7d8

Browse files
Update median doc to note return value of even-sized input
ghstack-source-id: d7825cd Pull Request resolved: #44562
1 parent c68a99b commit bcfd7d8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

torch/_torch_docs.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4577,6 +4577,12 @@ def merge_dicts(*dicts):
45774577
45784578
Returns the median value of all elements in the :attr:`input` tensor.
45794579
4580+
.. note::
4581+
The median is not unique for :attr:`input` tensors with an even number
4582+
of elements. In this case the lower of the two medians is returned. To
4583+
compute the mean of both medians in :attr:`input`, use :func:`torch.quantile`
4584+
with ``q=0.5`` instead.
4585+
45804586
.. warning::
45814587
This function produces deterministic (sub)gradients unlike ``median(dim=0)``
45824588
@@ -4604,6 +4610,12 @@ def merge_dicts(*dicts):
46044610
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
46054611
the outputs tensor having 1 fewer dimension than :attr:`input`.
46064612
4613+
.. note::
4614+
The median is not unique for :attr:`input` tensors with an even number
4615+
of elements in the dimension :attr:`dim`. In this case the lower of the
4616+
two medians is returned. To compute the mean of both medians in
4617+
:attr:`input`, use :func:`torch.quantile` with ``q=0.5`` instead.
4618+
46074619
.. warning::
46084620
``indices`` does not necessarily contain the first occurrence of each
46094621
median value found, unless it is unique.

0 commit comments

Comments
 (0)