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

Vector Addition in NumPyLearn to add NumPy vectors element by element with the + operator or numpy.add(), understand broadcasting, and handle vectors of unequal lengths. How to Sort Array by Column in NumPyLearn how to sort rows in a NumPy array by a selected column, sort by multiple keys, and distinguish row sorting from sorting each column independently. How to Rank Values in NumPy ArrayLearn how to rank values in a NumPy array with numpy.argsort() or scipy.stats.rankdata(), including rank numbering, tie handling, and descending order. NumPy PaddingLearn how to pad a NumPy array with numpy.pad, choose per-axis widths and modes, or build a zero-padded array manually. NumPy Magnitude in PythonThere are three main methods that can be used to find the magnitude of a vector in Python, the numpy.linalg.norm() function, the numpy.dot() function, and the numpy.einsum() function. NumPy Matrix SubtractionLearn how to subtract NumPy arrays element by element with the - operator and np.subtract(), and understand shape compatibility and broadcasting. How to Compare Two Arrays in PythonChoose a NumPy array comparison for exact values, floating-point tolerance, broadcasting, or elementwise checks. How to Divide Matrix by Vector in NumPyDivide each row of a NumPy matrix by a corresponding vector value using broadcasting, transpose, or reshape. Element-Wise Multiplication in NumPyLearn how to multiply NumPy arrays element by element with broadcasting and selected rows, columns, or subarrays. Array of Arrays in NumPyDiscover how to create and manipulate arrays of arrays in NumPy with our comprehensive guide. Learn about the numpy.array() function, slicing, reshaping, and more to enhance your data manipulation skills in Python. This article is perfect for anyone looking to master numerical data handling for data science and machine learning. One-Hot Encoding on NumPy Array in PythonThis tutorial demonstrates how to perform one-hot encoding on a numpy array in python How to Convert Matrix to Array in NumPyConvert a Python matrix to a NumPy array, keep its two-dimensional shape, or flatten it to one dimension with np.asarray(), np.array(), flatten(), ravel(), or reshape(-1). How to Multiply Array With Scalar in PythonLearn how to multiply every element of a NumPy array by a scalar in Python with either the * operator or numpy.multiply(). See runnable examples and how broadcasting applies. How to Remove Elements From Array in NumPyLearn how to remove NumPy array elements by position with numpy.delete() or by value with numpy.setdiff1d(). Cosine of Degree Values in NumPyThis tutorial demonstrates how to find cosine values for degrees in NumPy. Learn to efficiently calculate cosine values using built-in functions and custom methods, making your numerical computations in Python seamless. Explore examples and explanations that clarify the conversion from degrees to radians and the use of arrays for batch calculations. Perfect for beginners and experienced users alike, this guide will enhance your understanding of trigonometric functions in NumPy. NumPy Array EqualCompare NumPy arrays element by element, for exact whole-array equality, with broadcasting equivalence, or within a numeric tolerance. NumPy Intersection of Two ArraysDiscover how to find the intersection of two 1-dimensional arrays in Python using NumPy. This guide explores the numpy.isin() and numpy.intersect1d() methods, providing clear examples and explanations to enhance your data manipulation skills. Learn how to efficiently retrieve common elements and improve your programming practices with these powerful techniques. Overflow Encountered in numpy.exp() Function in PythonLearn how to handle overflow errors in the numpy.exp() function in Python. This article provides practical methods, including clipping input values, using logarithmic functions, and implementing conditional checks to avoid overflow. Enhance your programming skills and ensure smooth numerical computations with effective strategies for managing large input values. How to Convert NumPy Array to TupleLearn how to convert a NumPy array to a tuple in Python using tuple() and map(), with examples for one-dimensional and two-dimensional arrays. How to Delete Row in NumPyLearn how to delete rows from a NumPy array by index or condition. See how numpy.delete() uses axes and returns a new array, with examples for one row, multiple rows, and boolean filtering. How to NumPy Shuffle Two ArraysThere are three main methods that can be used to shuffle two corresponding arrays in Python, the sklearn.utils.shuffle() function, the numpy.random.shuffle() function, and the numpy.random.permutation() function. How to Convert Between `datetime.datetime`, `np.datetime64`, and `pd.Timestamp`Convert among Python datetime.datetime, NumPy datetime64, and pandas Timestamp with direct examples and notes on timezone and precision. How to Convert List to NumPy Array in PythonConvert a Python list to a NumPy array with numpy.array() or numpy.asarray(). Learn how nested lists determine array shape, when to choose a dtype, and when an existing compatible array may be reused. NumPy Unit VectorLearn how to normalize NumPy arrays to unit vectors in Python using two effective methods: the numpy.linalg.norm() function and a self-defined approach. This comprehensive guide provides clear code examples and detailed explanations to help you master vector normalization for your data science and numerical computing projects.