I've created PR#18386 to add a function called atleast_nd to numpy and numpy.ma. This would generalize the existing atleast_1d, atleast_2d, and atleast_3d functions.
I proposed a similar idea about four and a half years ago: https://mail.python.org/pipermail/numpy-discussion/2016-July/075722.html, PR#7804. The reception was ambivalent, but a couple of folks have asked me about this, so I'm bringing it back. Some pros: - This closes issue #12336 - There are a couple of Stack Overflow questions that would benefit - Been asked about this a couple of times - Implementation of three existing atleast_*d functions gets easier - Looks nicer that the equivalent broadcasting and reshaping Some cons: - Cluttering up the API - Maintenance burden (but not a big one) - This is just a utility function, which can be achieved through broadcasting and reshaping If this meets with approval, there are a couple of interface issues that probably need to be hashed out: - The consensus was that this function should accept a single array, rather than a tuple, or multiple arrays as the other atleast_nd functions do. Does that need to be revisited? - Right now, a `pos` argument specifies where to place new axes, if any. That can be specified in different ways. Another way might be to specify the offset of the existing dimensions, or something entirely different.
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@python.org https://mail.python.org/mailman/listinfo/numpy-discussion