MCPcopy
hub / github.com/dask/dask / median

Function median

dask/array/reductions.py:1484–1517  ·  view source on GitHub ↗

This works by automatically chunking the reduced axes to a single chunk if necessary and then calling ``numpy.median`` function across the remaining dimensions

(a, axis=None, keepdims=False, out=None)

Source from the content-addressed store, hash-verified

1482
1483@derived_from(np)
1484def median(a, axis=None, keepdims=False, out=None):
1485 """
1486 This works by automatically chunking the reduced axes to a single chunk if necessary
1487 and then calling ``numpy.median`` function across the remaining dimensions
1488 """
1489 if axis is None:
1490 raise NotImplementedError(
1491 "The da.median function only works along an axis. "
1492 "The full algorithm is difficult to do in parallel"
1493 )
1494
1495 if not isinstance(axis, Iterable):
1496 axis = (axis,)
1497
1498 axis = [ax + a.ndim if ax < 0 else ax for ax in axis]
1499
1500 # rechunk if reduced axes are not contained in a single chunk
1501 if builtins.any(a.numblocks[ax] > 1 for ax in axis):
1502 a = a.rechunk({ax: -1 if ax in axis else "auto" for ax in range(a.ndim)})
1503
1504 result = a.map_blocks(
1505 np.median,
1506 axis=axis,
1507 keepdims=keepdims,
1508 drop_axis=axis if not keepdims else None,
1509 chunks=(
1510 [1 if ax in axis else c for ax, c in enumerate(a.chunks)]
1511 if keepdims
1512 else None
1513 ),
1514 )
1515
1516 result = handle_out(out, result)
1517 return result
1518
1519
1520@derived_from(np)

Callers

nothing calls this directly

Calls 4

handle_outFunction · 0.90
anyMethod · 0.45
rechunkMethod · 0.45
map_blocksMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…