Python - Unique Values Multiplication

Pranay Arora
Updated on 27-Mar-2026 15:58:22

243 Views

Python lists allow duplicate values, which is useful in most cases. However, sometimes we need to remove duplicates and perform operations on unique values only. In this article, we'll explore multiple approaches to find unique values from a list and calculate their multiplication. Using set() to Remove Duplicates The set() function creates an unordered collection with no duplicate elements, making it perfect for extracting unique values ? def calculate_product(numbers): result = 1 for num in numbers: result *= num ... Read More

Python - Unique Tuple Frequency (Order Irrespective)

Pranay Arora
Updated on 27-Mar-2026 15:57:53

497 Views

In this article, we will find the frequency of unique tuples in a list where order doesn't matter. This means tuples like (1, 2, 3) and (1, 3, 2) are considered identical since they contain the same elements. Problem Understanding Input data = [(1, 2, 3), (2, 1, 3), (4, 5, 6), (1, 2, 3), (3, 2, 1)] print("Input:", data) Input: [(1, 2, 3), (2, 1, 3), (4, 5, 6), (1, 2, 3), (3, 2, 1)] Expected Output Frequency of unique tuples = 2 Explanation: Tuples at indices 0, ... Read More

Python - Uneven Sized Matrix Column Minimum

Pranay Arora
Updated on 27-Mar-2026 15:57:27

255 Views

In Python, when dealing with matrices of uneven row lengths, finding the minimum values in each column requires special handling. This article explores seven different methods to tackle this problem, from basic loops to advanced libraries like NumPy and Pandas. You'll learn how to handle uneven-sized matrices and extract column-wise minimum values efficiently using various approaches. Using Nested Loops This method iterates through the matrix using nested loops and tracks the minimum value for each column. It's straightforward but may be slower for large datasets ? matrix = [ [3, 8, ... Read More

Python - Tuple value product in dictionary

Pranay Arora
Updated on 27-Mar-2026 15:56:58

293 Views

Dictionaries in Python are widely used to store data in key-value pairs. Sometimes we need to calculate the product of elements at corresponding positions across tuple values in a dictionary. This commonly arises in data manipulation and analysis scenarios. Problem Statement Given a dictionary with tuples as values, we want to multiply elements at the same index positions across all tuples. Input input_dict = {'a': (1, 3, 5, 7), 'b': (2, 4, 6, 8), 'c': (2, 3, 5, 7)} print("Input:", input_dict) Input: {'a': (1, 3, 5, 7), 'b': (2, 4, 6, 8), 'c': ... Read More

How to Invert Python Tuple Elements?

Pranay Arora
Updated on 27-Mar-2026 15:56:27

547 Views

Python tuples store data in the form of individual elements with a fixed order. In this article, we'll explore various methods to invert (reverse) the order of tuple elements ? Sample Input and Output Input (5, 6, 7, 8) Output (8, 7, 6, 5) Using Tuple Slicing The most Pythonic way uses slice notation with step -1 to reverse the tuple ? original_tuple = (1, 2, 3, 4, 5) inverted_tuple = original_tuple[::-1] print("Original tuple:", original_tuple) print("Inverted tuple:", inverted_tuple) Original tuple: (1, 2, 3, 4, 5) ... Read More

Convert Lists into Similar key value lists in Python

Pranay Arora
Updated on 27-Mar-2026 15:56:05

281 Views

Converting two separate lists into a key-value mapping is a common data processing task in Python. The first list serves as keys, while the second list provides values. When keys repeat, their corresponding values are grouped together into lists. Example Input and Output keys = [3, 4, 3, 4, 5, 5] values = ['apple', 'banana', 'cherry', 'date', 'elderberry', 'fig'] # Expected output: # {3: ['apple', 'cherry'], 4: ['banana', 'date'], 5: ['elderberry', 'fig']} Using defaultdict with zip() The most efficient approach uses defaultdict to automatically create empty lists for new keys ? ... Read More

Divide one Hermite series by another in Python using NumPy

Niharika Aitam
Updated on 27-Mar-2026 15:55:42

192 Views

The Hermite series is a mathematical technique used to represent infinite series of Hermite polynomials. Hermite polynomials are orthogonal polynomials that solve the Hermite differential equation. NumPy provides functions to work with Hermite series, including division operations. What is a Hermite Series? A Hermite series is represented by the equation: f(x) = Σn=0^∞ cn Hn(x) Where: Hn(x) is the nth Hermite polynomial cn is the nth coefficient in the expansion Creating Hermite Series First, let's create Hermite series using NumPy's polynomial.hermite.poly2herm() function − import numpy as np from numpy.polynomial ... Read More

Divide a DataFrame in a ratio

Niharika Aitam
Updated on 27-Mar-2026 15:55:20

1K+ Views

Pandas DataFrames often need to be divided into smaller parts based on specific ratios for tasks like train-test splits in machine learning. Python provides several methods to split DataFrames proportionally using different approaches. There are three main ways to divide DataFrame data based on ratio: Using np.random.rand() Using pandas.DataFrame.sample() Using numpy.split() Using numpy.random.rand() This method creates random values for each row and filters based on a threshold. For a 60-40 split, we use 0.6 as the threshold ? Syntax import numpy as np ratio = np.random.rand(len(dataframe)) part1 = dataframe[ratio < threshold] ... Read More

Digital Band Pass Butterworth Filter in Python

Niharika Aitam
Updated on 27-Mar-2026 15:54:52

2K+ Views

A Band Pass Filter is a filter that passes frequencies within a specific range and rejects frequencies outside this range. The Butterworth band pass filter is designed to have the flattest possible frequency response in the pass band, making it ideal for applications requiring minimal ripple. Filter Specifications The following specifications define a typical digital band pass Butterworth filter: Sampling rate: 40 kHz Pass band edge frequencies: 1400 Hz to 2100 Hz Stop band edge frequencies: 1050 Hz to 2450 Hz Pass band ripple: 0.4 dB Minimum stop band attenuation: 50 dB Implementation Steps ... Read More

Differentiate Hermite series and multiply each differentiation by scalar using NumPy in Python

Niharika Aitam
Updated on 27-Mar-2026 15:54:26

163 Views

The Hermite_e series (probabilist's Hermite polynomial) is a mathematical function used in quantum mechanics and probability theory. NumPy provides the hermite.hermder() function to differentiate Hermite series and multiply each differentiation by a scalar value. Hermite_e Series Formula The Hermite_e polynomial is defined as: H_n(x) = (−1)^n e^(x²/2) d^n/dx^n(e^(−x²/2)) Where: H_n(x) is the nth Hermite polynomial of degree n x is the independent variable d^n/dx^n denotes the nth derivative with respect to x Syntax The polynomial.hermite.hermder() function syntax is: numpy.polynomial.hermite.hermder(c, m=1, scl=1, axis=0) Parameters: c − Array ... Read More

Advertisements