MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / mode

Function mode

monai/transforms/utils_pytorch_numpy_unification.py:426–438  ·  view source on GitHub ↗

`torch.mode` with equivalent implementation for numpy. Args: x: array/tensor. dim: dimension along which to perform `mode` (referred to as `axis` by numpy). to_long: convert input to long before performing mode.

(x: NdarrayTensor, dim: int = -1, to_long: bool = True)

Source from the content-addressed store, hash-verified

424
425
426def mode(x: NdarrayTensor, dim: int = -1, to_long: bool = True) -> NdarrayTensor:
427 """`torch.mode` with equivalent implementation for numpy.
428
429 Args:
430 x: array/tensor.
431 dim: dimension along which to perform `mode` (referred to as `axis` by numpy).
432 to_long: convert input to long before performing mode.
433 """
434 dtype = torch.int64 if to_long else None
435 x_t, *_ = convert_data_type(x, torch.Tensor, dtype=dtype)
436 o_t = torch.mode(x_t, dim).values
437 o, *_ = convert_to_dst_type(o_t, x)
438 return o
439
440
441def unique(x: NdarrayTensor, **kwargs) -> NdarrayTensor:

Callers 3

__call__Method · 0.90
test_modeMethod · 0.90
get_boxmodeFunction · 0.85

Calls 2

convert_data_typeFunction · 0.90
convert_to_dst_typeFunction · 0.90

Tested by 2

__call__Method · 0.72
test_modeMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…