np.round() Function in Python

np.round

While working on a data analysis project, I needed to round decimal values consistently across large NumPy arrays. The issue is that while Python has the built-in round() function, it doesn’t always work ideally with NumPy arrays and can behave unexpectedly with certain decimal values. This is where NumPy’s np.round() function becomes incredibly useful. In … Read more >>

NumPy’s np.abs() Function in Python

numpy abs

I was working on a data analysis project where I needed to calculate the absolute values of a large dataset. The issue is, while Python has a built-in abs() function, it’s not optimized for large numerical arrays. This is where NumPy’s np.abs() function comes to the rescue. In this article, I’ll cover everything you need … Read more >>

Mean Filter in Python NumPy

mean filter python 1

While I was working on an image processing project, I needed to reduce noise in some satellite images of national parks in the USA. The images had some grain that was making feature extraction difficult. This is where the mean filter (also called average filter) saved the day. In this article, I’ll share multiple ways … Read more >>

NumPy repeat(): Elements, Rows, Columns and vs tile

Python NumPy repeat: the Command Prompt comparing np.repeat against np.tile on the same array

np.repeat duplicates each element of a NumPy array in place, which is not the same as repeating the array: That difference is the thing to get straight first. After it, the argument that catches people is axis, which flattens your array when you leave it out. All output below is from real runs on Python … Read more >>

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 >>