Practical solutions

Python NumPy Howtos How-To Guides

Solve the problem. Keep building. Collection of Python NumPy how-to articles

Find the answer you need

Browse practical solutions, grouped by the task you're working on.

__COUNT__ entries on this page

How to Convert 3D Array to 2D Array in PythonLearn how to convert a 3D array to a 2D array in Python using the reshape() function from the NumPy library. This article provides practical examples and detailed explanations to help you manipulate multi-dimensional arrays efficiently. Discover the importance of shape compatibility and element order for seamless data transformation. Perfect for data scientists and programmers looking to enhance their array manipulation skills. How to Transpose a 1D Array in NumPyLearn how to transpose a 1D NumPy array in Python by reshaping it into a 2D format. This article covers practical methods using NumPy's reshape and newaxis functions, providing clear examples and explanations. Perfect for data manipulation in Python, especially in data science and machine learning contexts. Discover tips and techniques to enhance your array handling skills today! How to Reverse a NumPy Array in PythonReverse a NumPy array in Python with basic slicing, numpy.flipud(), or numpy.flip(), and choose the method by view and axis behavior. Element-Wise Division in Python NumPyDiscover how to perform element-wise division in Python using NumPy. Learn about the two main methods: numpy.divide() function and the / operator. This article provides clear examples and explanations to help you master element-wise operations in your data analysis projects. How to Convert Pandas Series to NumPy ArrayConvert the values of a pandas Series to a NumPy array with Series.to_numpy(), and choose compatible alternatives while keeping the index separate. How to Write NumPy Array to CSV in PythonThis tutorial demonstrates how to save a NumPy array in a CSV file using Python. Learn different methods, including NumPy's `savetxt`, Pandas DataFrame, and the CSV module. Follow along with clear examples and explanations to master exporting data efficiently. How to Find the First Index of Element in NumPy ArrayLearn how to find the first matching index in a NumPy array with np.where(), np.nonzero(), np.argmax(), list.index(), and a loop. Covariance in Python NumPyCalculate covariance in Python with numpy.cov(): what covariance means, a worked two-array example, the difference between sample and population normalization (bias/ddof), and how to read the covariance matrix. How to Calculate Absolute Value in NumPyLearn how to calculate absolute values in NumPy using three methods: abs(), numpy.absolute(), and numpy.abs(). This guide provides clear examples and explanations for each approach, making it easy to choose the right method for your data analysis needs. Enhance your Python skills and optimize your data manipulation with NumPy today. How to Get NumPy Array LengthUse len(array) for a NumPy array's first-axis length, array.size for its total element count, and array.shape for the length of each dimension. How to Create Empty NumPy ArrayLearn how to create empty NumPy arrays in Python using numpy.zeros() and numpy.empty(). This guide provides clear examples and detailed explanations for each method, helping you efficiently initialize arrays for your data manipulation tasks. Whether you're a beginner or an experienced programmer, you'll find valuable insights to enhance your coding skills. How to Save a NumPy Array as an Image in PythonThis tutorial demonstrates how to save a numpy array as image in Python. How to Get Number of Rows in NumPyThe array.shape property can be used to determine the number of rows and columns in a NumPy array in Python. NumPy FactorialLearn how to compute the factorial of the elements of a NumPy array using SciPy's special.factorial() function in Python, with code examples and explanations of the results, including why the values are returned as floating-point numbers and how to request exact integer results instead. How to Map a Function in NumPyApply a Python function to every value in a NumPy array with numpy.vectorize() or map() and a lambda. See how each approach works and when to use it. numpy.random.permutation() Function in NumPyThe numpy.random.permutation() function returns a randomly permuted copy of an array, or a permuted range of integers when given an integer, and leaves the original data unchanged — unlike numpy.random.shuffle(), which shuffles the array in place. How to Implement Bernoulli Distribution Using Python NumPyThis tutorial discusses what the Bernoulli distribution is and how to implement it in Python using NumPy. How to Iterate Over Rows of a Numpy Array in PythonThis tutorial discusses how to iterate over rows of a NumPy array in Python. NumPy mean() vs average()This tutorial demonstrates the difference between numpy.mean() and numpy.average() functions in Python. Learn how to calculate averages effectively with clear examples and understand when to use each method for your data analysis needs. How to Add a Row to a Matrix in NumPyThis tutorial demonstrates how to add a row to a matrix in NumPy, covering methods like vstack, append, and concatenate. Learn how to manipulate matrices efficiently and enhance your data analysis skills with practical code examples. Imaginary Numbers in NumPy ArraysThis tutorial demonstrates how to store and manipulate imaginary numbers in NumPy arrays. Learn to create complex number arrays, perform arithmetic operations, and access real and imaginary parts easily. Enhance your numerical computing skills with practical examples and explanations. Ideal for Python enthusiasts and engineers alike, this guide will help you leverage NumPy for complex number applications. Add a Dimension to a NumPy Array with numpy.newaxisUse numpy.newaxis in an array index to add a size-one dimension and form a row or column array. How to Replace Values in NumPyThere are three main methods that can be used to replace values inside a NumPy array in Python, the numpy.clip() function, the numpy.minimum() function, and the indexing method. How to Slice 2D Array in NumPyThere are several methods that we can utilize if we want to slice a 2-dimensional sub-array from a 2-dimensional array in Python. These methods include array indexing and numpy.ix_() function