May-05-2019, 09:05 AM
List Comprehension with conditional expression:
data = [0.16, 0, 0, 0.65, 0.17] result = [x * 2 if x < 0.5 else x for x in data]If you use numpy or pandas, you're using implicit for-loops. But in the numpy case, the for-loop is written in C. Operations on a numpy arrays are much faster than looping and doing the same in Python. To know how you can do broadcast operations with Python, is useful.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!