MCPcopy Create free account
hub / github.com/PythonOT/POT / median

Method median

ot/backend.py:2161–2178  ·  view source on GitHub ↗
(self, a, axis=None)

Source from the content-addressed store, hash-verified

2159 return torch.mean(a)
2160
2161 def median(self, a, axis=None):
2162 from packaging import version
2163
2164 # Since version 1.11.0, interpolation is available
2165 if version.parse(torch.__version__) >= version.parse("1.11.0"):
2166 if axis is not None:
2167 return torch.quantile(a, 0.5, interpolation="midpoint", dim=axis)
2168 else:
2169 return torch.quantile(a, 0.5, interpolation="midpoint")
2170
2171 # Else, use numpy
2172 warnings.warn(
2173 "The median is being computed using numpy and the array has been detached "
2174 "in the Pytorch backend."
2175 )
2176 a_ = self.to_numpy(a)
2177 a_median = np.median(a_, axis=axis)
2178 return self.from_numpy(a_median, type_as=a)
2179
2180 def std(self, a, axis=None):
2181 if axis is not None:

Callers

nothing calls this directly

Calls 3

to_numpyMethod · 0.80
from_numpyMethod · 0.80
medianMethod · 0.45

Tested by

no test coverage detected