How to Create a Custom Nested Index for Multidimensional Lists?

Problem Formulation Have you ever wanted to get the index of an item in a nightmarish nested list of lists of…, with different lengths and datatypes? Output: Well, you have found to the right place! 💬 Follow me through this step-by-step tutorial, and you’ll end up with an elegant functional solution to create a multi-dimensional … Read more

How to Generate a Sequence of Numbers

Problem Formulation and Solution Overview In this article, you’ll learn how to create a sequence of numbers in Python. To make it more fun, we have the following running scenario: Lux Lottery has decided to create a new Quick-Pick game called Lux-150. This game is based on seven (7) random numbers between 1 and 150 … Read more

How to Convert an Integer List to a String List in Python

The most Pythonic way to convert a list of integers ints to a list of strings is to use the one-liner strings = [str(x) for x in ints]. It iterates over all elements in the list ints using list comprehension and converts each list element x to a string using the str(x) constructor. This article … Read more

¿Cómo filtrar una lista en Python?

¿Cómo se puede filtrar una lista en Python utilizando una condición arbitraria? La forma más pitónica y más eficiente es utilizar la comprensión de lista [x for x in list if condition] para filtrar todos los elementos de una lista. Filtrar con comprensión de lista La forma más pitónica de filtrar una lista, en mi … Read more

Resampling A NumPy Array Representing An Image

Overview Resampling a Numpy array means changing the size of the matrix. The most efficient way to resample a numpy array representing an image is using scipy.ndimage.zoom function. The ndarray is the array to resample. The zoom part accepts either a single number or sequence. Inputting a single number implies the image will get zoomed … Read more

How to Apply a Function to NumPy Elements

Problem Formulation and Solution Overview As a Pythonista, coding issues may occur where you need to apply a function against NumPy elements. To make it more fun, we have the following running scenario: We have a NumPy array containing five (5) negative numbers related to an inconsistent inventory count. Therefore, the Vice-President of Rivers Clothing … Read more