Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
Python - Replace rear word in String
In this article, we will learn how to replace the rear (last) word in a string with any other given word. This is a common string manipulation task in Python programming. Let's understand this with an example ? original_string = "This cat is running very Fast" # We want to replace "Fast" with "Slow" # Result: "This cat is running very Slow" Method 1: Using split() and join() The most straightforward approach is to split the string into words, replace the last word, and join them back ? def replace_rear(text, new_word): ...
Read MorePython - Replace punctuations with K
In this article, we will learn how to replace punctuation marks with the letter "K" in Python strings. This is a common task in text processing and data cleaning operations where you need to replace punctuations with specific characters. Let's start with an example string ? original_string = "Welcome, to, * the website ! aliens" print("Original string:", original_string) Original string: Welcome, to, * the website ! aliens Our goal is to replace punctuation marks like ,, *, and ! with the letter "K", resulting in: "WelcomeK toK K the website K aliens". ...
Read MoreModelling the Gauss Seidel Method in Python
The Gauss-Seidel method is an iterative technique for solving systems of linear equations. Unlike the Jacobi method, Gauss-Seidel uses newly computed values within the same iteration, which speeds up convergence. Mathematical Foundation A system of linear equations can be written as: $$\mathrm{a_{1, 1}x_{1} \: + \: a_{1, 2}x_{2} \: + \: \dotso \: + \: a_{1, n}x_{n} \: = \: b_{1}}$$ $$\mathrm{a_{2, 1}x_{1} \: + \: a_{2, 2}x_{2} \: + \: \dotso \: + \: a_{2, n}x_{n} \: = \: b_{2}}$$ $$\mathrm{\vdots}$$ $$\mathrm{a_{n, 1}x_{1} \: + \: a_{n, 2}x_{2} \: + \: \dotso \: + \: a_{n, ...
Read MorePython - Replace negative value with zero in numpy array
In NumPy arrays, replacing negative values with zero is a common preprocessing step in data analysis. Python offers several efficient methods to accomplish this task, from basic list comprehension to NumPy's built-in functions. Using List Comprehension This approach converts the array to a list, applies conditional logic, and converts back to NumPy array − import numpy as np arr = np.array([-12, 32, -34, 42, -53, 88]) result = np.array([0 if x < 0 else x for x in arr]) print("Original array:", arr) print("Modified array:", result) Original array: [-12 32 -34 ...
Read MorePython Replace NaN values with average of columns
In this article, we will explore methods to replace NaN (Not a Number) values with the average of columns. When working with data analysis, handling NaN values is a crucial step. Here you will learn various approaches to replace NaN values with column averages using NumPy. Using numpy.nanmean() and numpy.where() The most straightforward approach uses nanmean() to calculate column averages and where() to replace NaN values ? import numpy as np arr = np.array([[1, 2, np.nan], [4, np.nan, 6], ...
Read MorePython - Replace multiple characters at once
In this article we will see methods to replace multiple characters at once in any string. When working with programs, we often face situations where we need to replace particular characters simultaneously at all their occurrences. Suppose you have text containing the word "word" with multiple occurrences and you want to convert "word" to "work" − doing this manually one by one is inefficient. Let's explore multiple methods to solve this problem efficiently. Using str.replace() Method This is the most straightforward method using Python's built-in replace function to replace desired characters ? Example string = ...
Read MorePython - Replace list elements with its ordinal number.
In this article, we will learn how to replace list elements with their ordinal numbers (position-based indices). An ordinal number represents the position of an item in a sequence, starting from 0 in programming. For example, in the list [6, 8, 5, 3], the ordinal values are: Element 6 has ordinal value 0 (first position) Element 8 has ordinal value 1 (second position) Element 5 has ordinal value 2 (third position) Element 3 has ordinal value 3 (fourth position) Let's explore various methods to replace nested list elements with their ordinal numbers. Using List ...
Read MoreJacobian matrix in PyTorch
In this article we will learn about the Jacobian matrix and how to calculate this matrix using different methods in PyTorch. We use Jacobian matrix in various machine learning applications. What is a Jacobian Matrix? The Jacobian matrix is a mathematical tool used to calculate the relationship between input and output variables. It contains all the partial derivatives of a vector-valued function. This matrix has various applications in machine learning and computational mathematics: Analyzing gradients and derivatives of functions in multivariable calculus Solving differential equations of systems Calculating inverse of vector-valued functions Analyzing stability of dynamic ...
Read MoreLumped Capacitance Analysis using Python
Lumped capacitance analysis is used when an object at high temperature is suddenly placed in a cooler medium. If the conductive resistance of the solid is much smaller than the convective resistance, we can treat the object as having uniform temperature throughout (a "lump"). The rate of internal energy change equals the heat transfer to the surrounding fluid. Hot Object T(t) Surrounding Fluid T∞ (constant) ...
Read MoreImplementation of Jacobi Method to Solve a System of Linear Equations in Python
The Jacobi Method is an iterative algorithm for solving systems of linear equations. It starts with initial guesses and repeatedly refines them until convergence is achieved. Mathematical Foundation Consider a system of linear equations: a₁₁x₁ + a₁₂x₂ + ... + a₁ₙxₙ = b₁ a₂₁x₁ + a₂₂x₂ + ... + a₂ₙxₙ = b₂ ... aₙ₁x₁ + aₙ₂x₂ + ... + aₙₙxₙ = bₙ The Jacobi method rearranges each equation to isolate one variable. For the i-th equation: xi = (bi - Σ(aijxj)) / aii The Jacobi Algorithm The algorithm follows these steps: ...
Read More