question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Truth ValueError in z_at_value() Function

See original GitHub issue

Description

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:closed
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
IsolatedSingularitycommented, Jul 20, 2022

Thanks 😃

1reaction
IsolatedSingularitycommented, Jul 13, 2022

Updating it has solved the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ValueError: The truth value of an array with more than one ...
If a and b are Boolean NumPy arrays, the & operation returns the elementwise-and of them: a & b. That returns a Boolean...
Read more >
How to Fix “ValueError: The truth value of an array with more ...
Let's start with the short one: Solution: Use the NumPy functions logical_and() and logical_or() instead of Python's logical operators “ and ” and...
Read more >
The truth value of a series is ambiguous. use a.empty, a.bool ...
This error occurs because the if statement requires a truth value, i.e., a statement evaluating to True or False . In the above...
Read more >
ValueError: Row: Invalid Input Type For Set Value
setValue built in function. I'm beginning to think that there is no way to edit feature classes that belong to a geometric network...
Read more >
ValueError: The truth value of an array with more than ... - GitHub
The error message "ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()" means that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found