Truth ValueError in z_at_value() Function
See original GitHub issueDescription
Consider an example from the tutorial on https://docs.astropy.org/en/stable/api/astropy.cosmology.z_at_value.html.
The input within the function argument is a list:
z_at_value(Planck13.age, [2, 7] * u.Gyr)
The expected output is:
<Quantity [3.19812061, 0.75620443] redshift>
However, when running it on my end I run into the following error:
ValueError Traceback (most recent call last)
c:\Users\Ocean\Desktop\research\Code\wakeSignal.py in <module>
----> 1 z_at_value(Planck13.age, [2, 7] * u.Gyr)
c:\Users\Ocean\anaconda3\lib\site-packages\astropy\cosmology\funcs.py in z_at_value(func, fval, zmin, zmax, ztol, maxfun, method, bracket, verbose)
203 fval_zmin, fval_zmax = func((zmin, zmax))
204 nobracket = False
--> 205 if np.sign(fval - fval_zmin) != np.sign(fval_zmax - fval):
206 if bracket is None:
207 nobracket = True
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Note, another inconsistency is the output of units following the Quantity class. For example in the tutorial we have:
z_at_value(Planck13.age, 2 * u.Gyr)
The expected output is:
<Quantity 3.19812268 redshift>
However, on my end the output is simply a float:
3.1981206134773115
Have you any idea what might be causing this issue? For context I am trying to pass a redshift array in the argument of z_at_value() so that I may scale an axis from Mpc to z (scaling an axis with a custom function requires both the normal function and its inverse which in this case is z_at_value).
Thanks in advance.
System Details
My system details output is: Windows-10-10.0.19042-SP0 Python 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)] Numpy 1.20.3 pyerfa 2.0.0 astropy 4.3.1 Scipy 1.7.1 Matplotlib 3.4.3
Issue Analytics
- State:
- Created a year ago
- Comments:5 (1 by maintainers)
Top GitHub Comments
Thanks 😃
Updating it has solved the issue.