ENH: Add support to ma.dot() for non-2d arrays with strict=True#23322
Conversation
ma.dot() for non-2d arrays with strict=Truema.dot() for non-2d arrays with strict=True
|
Was there a corresponding issue, or was this triggered by noticing the comments in the code? I am wondering if this has a wider audience fro the fix. |
numpy/ma/core.py
Outdated
| a = array(a, subok=False) | ||
| if a.ndim != 2: | ||
| raise NotImplementedError("mask_rowcols works for 2D arrays only.") | ||
| m = getmask(a) | ||
| # Nothing is masked: return a | ||
| if m is nomask or not m.any(): | ||
| return a | ||
| maskedval = m.nonzero() | ||
| a._mask = a._mask.copy() | ||
| if not axis: | ||
| a[np.unique(maskedval[0])] = masked | ||
| if axis in [None, 1, -1]: | ||
| a[:, np.unique(maskedval[1])] = masked | ||
| return a | ||
|
|
||
| if axis is None: | ||
| return _mask_propagate(a, axis=(0, 1)) | ||
| elif axis == 0: | ||
| return _mask_propagate(a, axis=1) | ||
| else: | ||
| return _mask_propagate(a, axis=0) | ||
|
|
There was a problem hiding this comment.
These changes don't seem to be necessary for the PR. Unless I'm wrong, it'd be best if you left this to a separate PR.
I don't have a stake in this, but if Numpy's going to have an ma.dot function, I think it should have the same capabilities as the normal dot function. |
| # with higher dimension | ||
| if strict and (a.ndim == 2) and (b.ndim == 2): | ||
| a = mask_rowcols(a, 0) | ||
| b = mask_rowcols(b, 1) |
There was a problem hiding this comment.
I guess mask_rowcols can now be moved to numpy/ma/extras.py rather than live in core.py
|
This deserves a mention in the release notes. See the directions in doc/release/upcoming_changes/README.rst |
|
Let's give this a shot. Thanks @F3eQnxN3RriK |
No description provided.