Eric Wieser wieser.eric+numpy at gmail.com
Fri Jan 17 05:39:24 EST 2020

```Today, numpy has a np.ma.mask_rowcols function, which stretches masks along
the full length of an axis. For example, given the matrix::

>>> a2d = np.zeros((3, 3), dtype=int)
>>> a2d[1, 1] = 1
>>> print(a2d)
[[0 0 0]
[0 -- 0]
[0 0 0]]

The API allows::

[[0 0 0]
[-- -- --]
[0 0 0]]

[[0 -- 0]
[0 -- 0]
[0 -- 0]]

[[0 -- 0]
[-- -- --]
[0 -- 0]]

However, this function only works for 2D arrays.
It would be useful to generalize this to work on ND arrays as well.

Unfortunately, the current function is messy to generalize, because axis=0
name is not particularly good for an ND function.

My proposal in PR 14998 <https://github.com/numpy/numpy/pull/14998> is to
introduce a new function, mask_extend_axis, which fixes this shortcoming.
Given an 3D array::

>>> a3d = np.zeros((2, 2, 2), dtype=int)
>>> a3d[0, 0, 0] = 1
>>> print(a3d)
[[[-- 0]
[0 0]]

[[0 0]
[0 0]]]

This, in my opinion, has clearer axis semantics:

[[[-- 0]
[0 0]]

[[-- 0]
[0 0]]]

[[[-- 0]
[-- 0]]

[[0 0]
[0 0]]]

[[[-- --]
[0 0]]

[[0 0]
[0 0]]]

Stretching over multiple axes remains possible:

[[[-- --]
[-- 0]]

[[0 0]
[0 0]]]

# extending sequentially is not the same as extending in parallel
[[[-- --]
[-- --]]

[[0 0]
[0 0]]]

Questions for the mailing list then:

- Can you think of a better name than mask_extend_axis?
- Does my proposed meaning of axis make more sense to you than the one