NumPy Meshgrid – A Simple Guide with Video

In Python, the numpy.meshgrid() function turns coordinate vectors into coordinate matrices.  What’s the purpose of np.meshgrid()? The grid-like coordinate matrices separate the values for each dimension and are used widely in matrix manipulation, data visualization, and machine learning.  Here is the argument table of numpy.meshgrid(). If it sounds great to you, please continue reading, and … Read more

np.argsort() — A Simpe Illustrated Guide

In Python, the numpy.argsort() function returns the indices that would sort an array in ascending order.  Here is the argument table of the numpy.argsort() function. If it sounds great to you, please continue reading, and you will fully understand the numpy.argsort() function through Python code snippets and vivid visualization. This tutorial is about numpy.argsort() function.  … Read more

np.gradient() — A Simple Illustrated Guide

In Python, the numpy.gradient() function approximates the gradient of an N-dimensional array. It uses the second-order accurate central differences in the interior points and either first or second-order accurate one-sided differences at the boundaries for gradient approximation. The returned gradient hence has the same shape as the input array.  Here is the argument table of … Read more

np.zeros() — A Simple Illustrated Guide

In Python, the numpy.zeros() function returns a new array of given shape and type, filled with zeros.  Here is the parameter table of numpy.zeros(). If it sounds great to you, please continue reading, and you will fully understand the numpy.zeros() function through Python code snippets and vivid visualization. Concretely, I will introduce its syntax and … Read more

np.where() – A Simple Illustrated Guide

Python’s numpy.where(condition, x, y) function returns an array with elements from x where condition is True, and elements from y elsewhere.  When simply calling numpy.where(condition), it is the shorthand of np.asarray(condition).nonzero() and returns a tuple containing the indices of elements that meets the condition for each dimension. If it sounds great to you, please continue … Read more

np.diff() — A Simple Illustrated Guide

In Python, the numpy.diff() function calculates the n-th discrete difference between adjacent values in an array along with a given axis. For higher-order differences calculation, numpy.diff() runs recursively to the output of the previous execution. Here is the argument table of numpy.diff(): If it sounds great to you, please continue reading, and you will fully … Read more

Python os.walk() – A Simple Illustrated Guide

According to the Python version 3.10.3 official doc, the os module provides built-in miscellaneous operating system interfaces. We can achieve many operating system dependent functionalities through it. One of the functionalities is to generate the file names in a directory tree through os.walk(). If it sounds great to you, please continue reading, and you will … Read more