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
np.full for Quantities #10836
Comments
You could also do: np.full(10, 1) << u.m But for the original request, perhaps @mhvk has an idea. If it is indeed a "won't fix," we should probably add it to https://docs.astropy.org/en/latest/known_issues.html . |
@nbiederbeck - thanks for raising the issue! Unfortunately, this is one of the very few numpy functions which we still cannot override (numpy allows only to override functions that take an array as an argument, so @pllim - you are right that we should add this to the known issues. One similarly cannot do |
Ok, thanks for your quick answers! |
If you are okay then, until a proper fix is in place, this would be simple enough for new contributors. |
@astrojuanlu , to avoid confusing new contributor, I wonder if we should open a new issue just to address the doc part of things. |
@astrojuanlu - thanks for raising the new issue. I marked the present one 'upstream fix required' since there are developments to make it work for numpy >=1.20 (though it would need an additional |
I just saw this due to the xref in numpy/numpy#17075, it seems like In [1]: import numpy as np, cupy as cp
In [2]: a = cp.ones(3)
In [3]: b = np.full_like(a, 7)
In [4]: b
Out[4]: array([7., 7., 7.])
In [5]: type(b)
Out[5]: cupy.core.core.ndarray
In [6]: b = np.full_like(a, 7, shape=(2, 2)) # You can override properties such as `shape`
In [7]: b
Out[7]:
array([[7., 7.],
[7., 7.]])
In [8]: type(b)
Out[8]: cupy.core.core.ndarray |
I see now that the above has already been proposed in #10836 (comment). Note that |
@pentschev - indeed,
works. It would have been nice if the |
Given that |
@pentschev - yes, no problem! I don't quite think this is worth (slightly) changing the numpy API for. |
Update: |
Update with astropy 5.2.1 , it no longer throw exception but it also loses unit. >>> np.full(10, my_quantity)
array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]) |
Description
I try to do
but get
What I want is what I get via
but the first version is so much cleaner.
Is there a (better) way to do this, or a chance to implement this?
The text was updated successfully, but these errors were encountered: