Python Check Version of Package with pip

Problem Formulation Assuming you have the Python package manager pip installed in your operating system (Windows, Linux, macOS). How to check the version of a package with pip? Method 1: pip show To check which version of a given package is installed, use the pip show <your_package> command. For example, to check the version of … Read more

How to Find Outliers in NumPy Easily?

Can you spot the outliers in the following sequence: 000000001000000001? Detecting outliers fast can be mission critical for many applications in military, air transport, and energy production. This article shows you the most basic outlier detection algorithm: if an observed value deviates from the mean by more than the standard deviation, it is considered an … Read more

How to Filter in Python using Lambda Functions?

To filter a list in Python, you can use the built-in filter() function. The first argument is the filtering condition, defined as a function. This filtering condition function is often dynamically-created using lambda functions. The second argument is the iterable to be filtered—the lambda function checks for each element in the iterable whether the element … Read more

Python Operator Precedence

If you use multiple operators in a single expression, the semantics of that expression depends on the assumed operator precedence. For example, consider the expression 2 + 4 * 0. Does Python calculate (2 + 4) * 0 or 2 + (4 * 0)? Depending on the operator precedence, the result would be 0 or … Read more

NumPy Sort [Ultimate Guide]

The np.sort(array) function returns a sorted copy of the specified NumPy array. Per default, it sorts the values in ascending order, so np.sort([42, 2, 21]) returns the NumPy array [2 21 42]. Here’s an example of 1D sorting: And here’s an example of 2D sorting — each axis is sorted separately. An example of 3D … Read more

How to Use Slice Assignment in NumPy?

NumPy slice assignment allows you to use slicing on the left-hand side of an assignment operation to overwrite a specific subsequence of a NumPy array at once. The right side of the slice assignment operation provides the exact number of elements to replace the selected slice. For example, a[::2] = […] would overwrite every other … Read more

Python is Operator — Checking Identity

The Python is keyword tests if the left and right operands refer to the same object—in which case it returns True. It returns False if they are not the same object, even if the two objects are equal. For example, the expression [1, 2, 3] is [1, 2, 3] returns False because although both lists … Read more