Python Articles

Page 14 of 855

Python - Uneven Sized Matrix Column Minimum

Pranay Arora
Pranay Arora
Updated on 27-Mar-2026 250 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
Pranay Arora
Updated on 27-Mar-2026 292 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
Pranay Arora
Updated on 27-Mar-2026 541 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
Pranay Arora
Updated on 27-Mar-2026 277 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
Niharika Aitam
Updated on 27-Mar-2026 188 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
Niharika Aitam
Updated on 27-Mar-2026 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
Niharika Aitam
Updated on 27-Mar-2026 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
Niharika Aitam
Updated on 27-Mar-2026 160 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

Difference between casefold() and lower() in Python

Pranavnath
Pranavnath
Updated on 27-Mar-2026 947 Views

Python provides two similar string methods for converting text to lowercase: casefold() and lower(). While they appear similar, they handle Unicode characters differently, making each suited for specific use cases. Understanding casefold() The casefold() method performs aggressive case folding by converting characters to lowercase and normalizing special Unicode characters. This makes it ideal for case-insensitive comparisons across different languages. Example text = "Déjà Vuß" result = text.casefold() print(result) déjà vuss Notice how the German ß character is converted to "ss" for more accurate comparison. Understanding lower() The lower() ...

Read More

Python calendar module : monthdays2calendar() method

Pranavnath
Pranavnath
Updated on 27-Mar-2026 383 Views

The Python calendar module provides various methods for working with dates and calendars. The monthdays2calendar() method is particularly useful for generating structured calendar layouts that include both day numbers and their corresponding weekday information. What is monthdays2calendar()? The monthdays2calendar() method returns a matrix representing a month's calendar where each day is paired with its weekday number. Unlike monthcalendar() which returns only day numbers, this method provides tuples of (day, weekday) for each position in the calendar grid. Syntax calendar.Calendar().monthdays2calendar(year, month) Parameters year − The year as a four-digit integer month − ...

Read More
Showing 131–140 of 8,549 articles
« Prev 1 12 13 14 15 16 855 Next »
Advertisements