NumPy Normalize Array Between 0 and 1

numpy normalize

When working with numerical data in Python, normalization is a common preprocessing step that can significantly improve the performance of machine learning algorithms. Recently, I was analyzing US housing price data and needed to normalize the values between 0 and 1 to make my model more effective. The issue was that the raw data had … Read more >>

NumPy unique: Values, Counts and Unique Rows

NumPy unique: the Command Prompt showing unique values with their counts and the most common value

np.unique() returns the distinct values of a NumPy array, sorted, with duplicates removed. Add return_counts=True and you get how often each one appeared: The sorting is not optional, which is the first thing that surprises people coming from pandas. The axis argument is the second. Runs below are on NumPy 2.5.3, pandas 3.0.6, Python 3.12.5. … Read more >>

NumPy uint8 (np.uint8) in Python: Range, Conversion and Overflow

NumPy uint8 in Python: Command Prompt output of uint8 overflow, subtraction wraparound and clipping

np.uint8 is NumPy’s unsigned 8-bit integer data type: every value uses one byte and must be a whole number from 0 to 255. That makes it the standard type for image pixels and other compact data. Create a uint8 array with np.array(values, dtype=np.uint8) or convert one with arr.astype(np.uint8), but watch out: values outside 0–255 wrap … Read more >>

Np.where In Pandas Python

np.where pandas

As a Python developer with over a decade of experience, I’ve found that data manipulation tasks often come down to filtering and finding specific values. One of the most efficient tools in the Python data science ecosystem is np.where(), especially when used with Pandas. In this comprehensive guide, I’ll walk you through everything you need … Read more >>

NumPy Shape in Python: shape[0], shape[1] and the Tuple

NumPy shape: the Command Prompt showing shape[0] as the row count and shape[1] as the column count

NumPy shape is an attribute, not a function. It hands you a tuple with one entry per dimension, and you read it with no parentheses at all: That single detail explains most of the errors people hit with it. The rest of this guide covers what the tuple means, what shape[0] and shape[1] actually count, … Read more >>

NumPy Empty Array: np.empty(), Zero-Length Arrays and dtype

NumPy empty array: the Command Prompt showing np.empty returning uninitialised leftover values

A NumPy empty array comes from np.empty(), which reserves memory without clearing it first: Those are two separate ideas that share a name. np.empty(5) has five slots full of junk, while np.array([]) genuinely holds nothing. Timings and output below come from Python 3.12.5, NumPy 2.5.3 on this machine. What np.empty actually returns The values are … Read more >>

How NumPy Create NaN Array in Python?

numpy nan

I was working on a data analysis project for a US retail chain where I needed to handle missing sales data. The issue was, I needed to create placeholder arrays filled with NaN (Not a Number) values that would later be populated with actual data. In this article, I’ll share several practical methods to create … Read more >>

NumPy zeros(): Create Arrays of Zeros with np.zeros

NumPy zeros: Command Prompt showing np.zeros creating 2D and 3D arrays and the shape of np.zeros((3, 2))

np.zeros() creates a NumPy array of a given shape filled with zeros. Pass one number for a 1D array or a tuple for more dimensions, and add dtype if you don’t want floats: Below I cover the shape rules, dtypes, zeros_like(), how it compares with np.empty(), and the errors people hit. Everything ran on Python … Read more >>

How to Read CSV Files with Headers Using NumPy in Python

numpy load csv

While working on a data analysis project, I needed to import CSV files with header rows into my Python application. While Pandas is often the go-to library for this task, I needed the performance benefits and numerical capabilities of NumPy. The challenge is that NumPy doesn’t handle headers as intuitively as Pandas does. In this … Read more >>