-
Notifications
You must be signed in to change notification settings - Fork 47
A helper function that removes singleton dimensions #974
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
Comments
You mean like dropdims? |
A wrapper around |
maybe |
Would that just be: dropsingletondims(x) = dropdims(x; dims = filter(d -> length(d) == 1, dims(x))) ? It seems to work on simple cases |
Yup... that's seems to do the job... the question is would others find it helpful... |
Seems like something generally missing in Julia more than just missing in DD? Which makes me cautious to add it |
Fair enough. There is a good discussion here. I am wondering if DD is a bit unique in the need to remove singleton dims... I find myself often needing to remove singleton dims after using reducer function as the singleton dim often has no valuable meaning ... like when taking the mean of data grouped by month (I understand that the dim is technically correct). If this is something others do often then a |
I think I agree with Tim Holys take in the thread. It encourages something slow and potentially buggy to be frequently used. I know the alternative is annoying boilerplate, but our quest for perfect syntax will inevitably end somewhere short of perfect ;) |
Yeah, the way this basically nukes array dimension inference means you really don't want this in package code (but user level might be fine if you aren't precompiling) |
There is also this julia issue where it came up JuliaLang/julia#28906 and where Tim Holy also advised against it. |
Good discussion ... closing issue as this functionality is not best practice |
I could be useful to have a helper function that strips singleton dimensions from a DimArray... something akin to Matlab's
squeeze
:https://www.mathworks.com/help/matlab/ref/squeeze.html
The text was updated successfully, but these errors were encountered: