oneflow.median¶
-
oneflow.
median
(input) → Tensor¶ Returns the median of the values in input. The documentation is referenced from: https://pytorch.org/docs/1.10/generated/torch.median.html#torch.median
Note
The median is not unique for
input
tensors with an even number of elements. In this case the lower of the two medians is returned.- Parameters
input (Tensor) – the input tensor.
For example:
>>> import oneflow as flow >>> x = flow.tensor((1, 2, -1), dtype=flow.float32) >>> flow.median(x) tensor(1., dtype=oneflow.float32)
-
oneflow.
median
(input, dim=- 1, keepdim=False, *, out=None)
Returns a tuple
(values, indices)
wherevalues
contains the median of each row ofinput
in the dimensiondim
, andindices
contains the index of the median values found in the dimensiondim
.By default,
dim
is the last dimension of theinput
tensor.If
keepdim
isTrue
, the output tensors are of the same size asinput
except in the dimensiondim
where they are of size 1. Otherwise,dim
is squeezed (seeflow.squeeze()
), resulting in the outputs tensor having 1 fewer dimension thaninput
.Note
The median is not unique for
input
tensors with an even number of elements in the dimensiondim
. In this case the lower of the two medians is returned.- Parameters
input (Tensor) – the input tensor.
dim (int) – the dimension to reduce.
keepdim (bool) – whether the output tensor has
dim
retained or not.
For example:
>>> import oneflow as flow >>> a = flow.tensor([[ 0.2505, -0.3982, -0.9948, 0.3518, -1.3131], ... [ 0.3180, -0.6993, 1.0436, 0.0438, 0.2270], ... [-0.2751, 0.7303, 0.2192, 0.3321, 0.2488], ... [ 1.0778, -1.9510, 0.7048, 0.4742, -0.7125]]) >>> result=flow.median(a, 1) >>> result.values tensor([-0.3982, 0.2270, 0.2488, 0.4742], dtype=oneflow.float32) >>> result.indices tensor([1, 4, 4, 3], dtype=oneflow.int64)