I'm currently going through the book called python for data analysis.
There's a part about finding outliers and it looks something like this (check the code).
Although it doesn't look hard at first glance it made me realise that I don't really understand python's any function even though it appears to be easy.
Most resources I checked just mention things like "any() is a built-in function in Python 3, to check if any of the items of an iterable 14 is True. It takes one argument, iterable." source (https://www.freecodecamp.org/forum/t/python-any-iterable/19210)
This simple definition I understand by in this example how is the number 1 an iterable? I've checked the code and it does somehow require this 1. Also the python documentation only mentions it being an built-in function that takes an argument in the parenthesis which is an iterable. However, there is lacking information of how any is used as a method like in the example below.
python documentation for built-in functions: https://docs.python.org/3/library/functions.html#any
Please could someone enlighten me? (Main parts of the questions have been bolded for clarity)
data[(np.abs(data)>0.8).any(1)]
That is because the any you have here is not the builtin one, but rather the numpy one. In you console try:
help(any)
and
help(np.array(1).any)
to see the difference. any in your case is the axis to check if any value along said axis evaluates to True.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With