Jupyter/pandas - any() command issue

Guys… going through the Data Analysis Course, and I believe there is a mistake in the exercises but wanted to make sure I wasn’t missing something about the any() command.

The challenge is to write a statement that’s True if any element is Zero, but the answer they give will actually return true if any element isn’t 0 I believe. Same problem in the Numpy exercise as well.

Below was my answer after some playing around with any, and I illustrated that the answer provided still shows True even when no element is 0.

So question is, am I missing something, or is the provided solution wrong? Also, I spent some time trying to figure out how I could use X.any() to actually give the right answer, including X.any(where=0) but couldn’t find a way, and all research showed answers for np.any(), such as np.any(X==0) which is basically my answer, but nothing for np.array.any()… even numpys documents refer you to np.any() when trying to research np.array.any(). Is there a way to do it?

I’m probably digging way to much into what is really a non-issue, but once curiousity is peeked, not much I can do.

From what I can understand from the docs about any,
If any value in a list, tuple, dict, etc… are True, then True will be returned. If all items are False then False is returned. If there is a mix, True will be returned.

Exactly, but the requested problem was to return True if any elements are Zero, which seems the opposite of what Any would do… just wondering if there is a way to use np.array.any() to solve this problem without turning to np.any().

Thanks… that all makes since… but in the exercises its suggesting to use arr.any()… not np.any(arr)… thats what confused me and I couldn’t find any good documentation on how to use arr.any() other than just if return true if any values are true. Seems just an issue with the exercise guide. Thanks for all the info :slight_smile:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.