Numpy Articles

Page 3 of 81

How to Count the Frequency of Unique Values in NumPy Array?

Prince Yadav
Prince Yadav
Updated on 27-Mar-2026 11K+ Views

Analyzing the frequency of unique values within a NumPy array is a common task in data analysis. It provides valuable insights into the distribution and occurrence of elements, enabling effective data exploration and preprocessing. In this article, we will explore various methods to count the frequency of unique values in NumPy arrays using built-in NumPy functions and external libraries. Method 1: Using np.unique() Function NumPy provides the np.unique() function, which returns the sorted unique elements of an array. By specifying the return_counts=True parameter, it also returns the count of each unique element ? import numpy as ...

Read More

How to Convert NumPy datetime64 to Timestamp?

Prince Yadav
Prince Yadav
Updated on 27-Mar-2026 6K+ Views

When working with dates and times in Python, NumPy's datetime64 data type provides efficient storage for temporal data. However, you may need to convert these objects to pandas Timestamp format to access pandas' extensive time-series functionality. Converting NumPy datetime64 to Timestamp unlocks powerful capabilities for time-series analysis, data manipulation, and visualization. This conversion enables working with time-indexed data, performing date arithmetic, and applying various time-related operations. Using pd.Timestamp() The most direct approach is using pandas' Timestamp() constructor, which seamlessly converts NumPy datetime64 objects ? import numpy as np import pandas as pd # Create ...

Read More

Print Full Numpy Array without Truncation

Shriansh Kumar
Shriansh Kumar
Updated on 27-Mar-2026 10K+ Views

NumPy is a powerful Python library for handling large, multi-dimensional arrays. However, when printing large NumPy arrays, the interpreter often truncates the output to save space and shows only a few elements with ellipsis (...). In this article, we will explore how to print a full NumPy array without truncation. Understanding the Problem To understand the truncation issue, consider this example: import numpy as np # Create a large array with 1100 elements array = np.arange(1100) print(array) [ 0 1 2 ... 1097 1098 ...

Read More

How to Convert an Image to a NumPy Array and Save it to a CSV file using Python?

Prince Yadav
Prince Yadav
Updated on 27-Mar-2026 978 Views

Python is a powerful programming language with a vast array of libraries and modules. One such library is NumPy, which is used for numerical computing and processing large multidimensional arrays and matrices. Another popular library used for image processing in Python is Pillow, which is a fork of the Python Imaging Library (PIL). In this tutorial, we will show you how to convert an image to a NumPy array and save it to a CSV file using Python. We will be using the Pillow library to open the image and convert it to a NumPy array, and NumPy's built-in ...

Read More

How to Convert a Dictionary into a NumPy Array?

Prince Yadav
Prince Yadav
Updated on 27-Mar-2026 865 Views

Python's NumPy library provides powerful tools for working with structured data. When dealing with dictionary data, you may need to convert it to NumPy arrays for mathematical operations and data analysis. This tutorial will show you how to convert both simple and nested dictionaries into NumPy arrays using various methods. Converting a Simple Dictionary Let's start by converting a basic dictionary with key-value pairs − import numpy as np my_dict = {'a': 1, 'b': 2, 'c': 3, 'd': 4} # Convert dictionary items to NumPy array my_array = np.array(list(my_dict.items())) print("Dictionary items as array:") ...

Read More

What is Standardization in Machine Learning

Jaisshree
Jaisshree
Updated on 27-Mar-2026 1K+ Views

Standardization is a crucial preprocessing technique in machine learning that ensures all features are on the same scale. This process transforms data to have a mean of 0 and a standard deviation of 1, making features comparable and improving model performance. What is Standardization? Standardization, also known as Z-score normalization, is a feature scaling technique that transforms data by subtracting the mean and dividing by the standard deviation. This process ensures that all features contribute equally to machine learning algorithms that are sensitive to feature scale. Mathematical Formula The standardization formula is ? Z ...

Read More

Medical Insurance Price Prediction using Machine Learning in Python

Jaisshree
Jaisshree
Updated on 27-Mar-2026 842 Views

Medical insurance price prediction helps insurance companies assess risk and set appropriate premiums. Using machine learning, we can analyze historical data to predict insurance costs based on factors like age, BMI, smoking habits, and medical history. In this tutorial, we'll build a predictive model using a medical insurance dataset to estimate insurance charges for individuals based on their personal characteristics. Dataset Overview The medical insurance dataset contains the following features: age − Age of the individual sex − Gender (male/female) bmi − Body Mass Index children − Number of dependents smoker − Smoking status (yes/no) ...

Read More

How to Compute Derivative Using Numpy?

Prince Yadav
Prince Yadav
Updated on 27-Mar-2026 10K+ Views

Calculus, the study of continuous change, is a fundamental subject in mathematics that has numerous applications in fields ranging from physics to economics. One of the key concepts in calculus is derivative, which measures the instantaneous rate of change of a function at a given point. The derivative of function f(x) at point x is mathematically defined as ? f'(a) = lim(h -> 0) [(f(a+h) - f(a))/h] However, computing derivatives by hand can be time−consuming and error−prone. NumPy provides the gradient() function to calculate derivatives quickly and accurately for both one−dimensional and multi−dimensional functions. ...

Read More

How to Compute Cross-Correlation of two given Numpy Arrays?

Prince Yadav
Prince Yadav
Updated on 27-Mar-2026 2K+ Views

Cross-correlation is a concept widely used in signal processing and image processing to determine the similarity between two signals or images. Python offers an efficient way to compute cross-correlation between numpy arrays using the numpy.correlate() function. The NumPy library provides numpy.correlate() for calculating cross-correlation of one-dimensional arrays. For two-dimensional arrays, we need to flatten them first and then use the same function. Syntax The syntax of the numpy.correlate() function is ? numpy.correlate(a, v, mode='valid') Parameters a, v ? Input arrays to calculate cross-correlation mode ? Size of output array ('valid', 'same', ...

Read More

Load NumPy data in Tensorflow

Siva Sai
Siva Sai
Updated on 27-Mar-2026 543 Views

TensorFlow provides seamless integration with NumPy arrays through the tf.data.Dataset.from_tensor_slices() function. This allows you to convert NumPy arrays into TensorFlow datasets, enabling efficient data processing and model training. Prerequisites Make sure that your Python environment has NumPy and TensorFlow installed − pip install numpy tensorflow Basic NumPy Array Loading The simplest way to load NumPy data into TensorFlow is using tf.data.Dataset.from_tensor_slices() ? import numpy as np import tensorflow as tf # Create a NumPy array numpy_data = np.array([1, 2, 3, 4, 5]) # Load the NumPy data into TensorFlow ...

Read More
Showing 21–30 of 802 articles
« Prev 1 2 3 4 5 81 Next »
Advertisements