-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
ENH: Added fill
option to np.atleast_2d
and np.atleast_3d
#25170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Can someone help me fix the failed build / give some feedback? |
fill
option to np.atleast_2d
and np.atleast_3d
fill
option to np.atleast_2d
and np.atleast_3d
Up |
fd4913c
to
7e09862
Compare
Dear, @melissawm @charris, thank you both for having shown interest at some point. Do you think it is possible to get this PR reviewed or even discussed at some point? What would the procedure be? Because I do feel a bit unconfortable directly pinging you for attention. But I don't know any solution to get it out of the abyss! Thanks! |
Somewhat related? data-apis/array-api#494 |
We discussed this in a recent triage meeting. Since there is no corresponding issue, could you explain the motivation? I did see #25805 about consistency with left-right and |
Thank you for your comment. I do think that new_ary = np.atleast_nd(ary, nd, fill) with fill (str | Iterable[int]): Where to add missing dimensions, if any. If
a string, it must be one of ``{'left', 'right'}``. Otherwise, it
must be a permutation of ``np.arange(nd)``, in which case missing
dimensions will be added in axes indexed by ``fill[:nd-ary.ndim]``. This could be even more permissive in a few ways. For example
Also, still with The current implementations of np.atleast_nd(ary, 2, fill='left') # current `atleast_2d`
np.atleast_nd(ary, 3, fill=(2, 0, 1)) # current `atleast_3d`
np.atleast_nd(ary, 3, fill=(-1, 'left')) # another possible syntax for current `atleast_3d` For my PR, I only focused on a small modification, to avoid going through a long discussion / approval process required to add a new method. The use cases can be plenty. A simple one would be to allow a user to call a function treating 2d arrays by passing either one 2d array or a batch of 2d arrays (so a 3d tensor with This can feel silly, but I'm pretty sure there numerous use cases, especially with Thanks! |
Any feedback? I think it is reasonable to merge this as it is a very very light and compatible change, providing more flexibility. As seen above, the implementation of |
Closes #25805 since it provides override option.
Added optional keyword argument
fill
tonp.atleast_2d
andnp.atleast_3d
, to specify where the missing dimension(s) should be added.np.atleast_1d
for obvious reasons, but if signature consistency is an issue, it can be done,This can be useful when working with Fortan convention for example, or for locally-specifi reasons.
Illustrative examples: