How to Get the Row with Minimal Variance in NumPy

You may have read about the β€˜V’s in Big Data: Volume, Velocity, Variety, Veracity, Value, Volatility. Variance is yet another important β€˜V’ (it measures Volatility of a data set). In practice, variance is an important measure with important application domains in financial services, weather forecasting, and image processing. Variance measures how much the data spreads … Read more

How to Return Dictionary Keys as a List in Python?

Short answer: use the expression list(dict.keys()). Problem Formulation Given a dictionary that maps keys to values. Return the keys as a list. For example: Given dictionary {‘Alice’: 18, ‘Bob’, 21, ‘Carl’: 24} Return the keys as a list [‘Alice’, ‘Bob’, ‘Carl’] Solution The dict.keys() method returns a list of all keys in Python 2. The … Read more

How to Concatenate Two NumPy Arrays?

Problem Formulation Given two NumPy arrays a and b. How to concatenate both? Method 1: np.concatenate() NumPy’s concatenate() method joins a sequence of arrays along an existing axis. The first couple of comma-separated array arguments are joined. If you use the axis argument, you can specify along which axis the arrays should be joined. For … Read more

Python Not Operator

Python’s not operator returns True if the single operand evaluates to False, and returns False if it evaluates to True. Thus, it logically negates the implicit or explicit Boolean value of the operand. As you read through the article, you can also watch my video for supporting explanations: Python Not Operator on Boolean You can … Read more

How to Find Path Where Python is Installed on Windows?

Windows normally installs Python on one of the two locations: C:\Python39 C:\Users\YourUser\AppData\Local\Programs\Python\Python39 For me, it’s the latter. For you, it may be different—this article shows you how to check for yourself! πŸ™‚ For your convenience, I’ve made a short gif that shows how I rushed through the code on my Windows machine: Before you start, … Read more

Python Or Operator

Python’s or operator performs the logical OR operation that returns True if at least one of the operands evaluates to True. The operator performs an optimization called short-circuiting, so if the first operand evaluates to True, it returns the first right away without further evaluating the second, and if the first operand evaluates to False, … Read more

Python And Operator

Python’s and operator performs the logical AND operation that returns True if both operands evaluate to True. The operator performs an optimization called short-circuiting, so if the first operand evaluates to True, it returns the second operand; and if the first operand evaluates to False, it returns False without further evaluating the second operand. As … Read more

Python Exponent – 4 Operators Every Coder Must Know

Python has four ways to calculate the n-th power (exponent) of x so that xⁿ=x*x*…*x that multiplies the base x with itself, and repeating this n-times. Method 1: Use the double-asterisk operator such as in x**n. Method 2: Use the built-in pow() function such as in pow(x, n). Method 3: Import the math library and … Read more