Found 10784 Articles for Python

Python - Replace rear word in String

Kalyan Mishra
Updated on 03-Oct-2023 15:42:20

78 Views

In this article we will learn how we can replace rear (word at the end of the string) word with any other given word. You may have seen this problem while doing manipulation of string. Here we will see various methods for replacing the rear word in string with given word. Let’s get to know this using below example − string_txt = "This cat is running very Fast" Here we have a string string_txt which contains sentences and we want to replace the last word which is "Fast" into "Slow" so that the resulting string will be like. ... Read More

Python - Replace punctuations with K

Kalyan Mishra
Updated on 03-Oct-2023 15:40:12

56 Views

In this article we will learn about replacement of punctuation with letter k in the string. You may have seen this problem while performing text processing or data cleaning task in the python where you need to replace punctuations with specific characters or any symbol. Here we will see various methods for replacing the punctuations with given text "k" Let’s get to know this using below example − string = "Welcome, to, * the website ! aliens" Here we have a string which contains punctuations like [, * !] and we want to replace that with text "k". ... Read More

Modelling the Gauss Seidel Method in Python

Dr Pankaj Dumka
Updated on 03-Oct-2023 13:47:54

2K+ Views

Gauss Seidel Method is the iterative method to solve any system of linear equations. Though the method is very much similar to the Jacobi's method but the values of unknown (x) obtained in an iteration are used in the same iteration in Gauss Seidel whereas, in Jacobi's method they are used in the next iteration level. The updation of x in the same step speeds up the convergence rate. A system of liner equation 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, ... Read More

Python - Replace negative value with zero in numpy array

Kalyan Mishra
Updated on 03-Oct-2023 15:37:32

1K+ Views

In this article we will see method to replace negative values with zero. If we talk about data analysis then handling negative values is very crucial step to ensure meaningful calculation. So, here you will learn about various methods using which we can replace negative values with 0. Method 1. Using Traversal and List Comprehension. Example import numpy as np arr = np.array([-12, 32, -34, 42, -53, 88]) arr = [0 if x < 0 else x for x in arr] arr = np.array(arr) print("array with replaced values is: ", arr) Output array with replaced values ... Read More

Python Replace NaN values with average of columns

Kalyan Mishra
Updated on 03-Oct-2023 15:35:51

285 Views

In this article we will see method to replace NaN (Not a Number) value with the average of columns. If we talk about data analysis then handling NaN value is very crucial step. So, here you will learn about various methods using which we can replace NaN (Not a Number) value with the average of columns. Method 1: Using Numpy.nanmean(). Example import numpy as np arr = np.array([[1, 2, np.nan], [4, np.nan, 6], [np.nan, 8, 9]]) col_means = np.nanmean(arr, axis=0) arr_filled = np.where(np.isnan(arr), col_means, arr) print("Column mean: ", col_means) print("Final array: ... Read More

Python - Replace multiple characters at once

Kalyan Mishra
Updated on 03-Oct-2023 15:26:07

5K+ Views

In this article we will see method to replace the multiple characters at once in any string. While working with programs where we face such situation when we will have to replace any particular character simultaneously at all of its occurences. Suppose a situation in which you have an article in which it contains one word named as “word” which is having multiple occurrences and you want to convert that “word” into “work” so you can do this manually but it is very bad practice of doing this work one by one. So, we will look at multiple methods using ... Read More

Python - Replace list elements with its ordinal number.

Kalyan Mishra
Updated on 03-Oct-2023 15:15:47

118 Views

In this article we will learn how to replace any given list element with its ordinal number. We will see various methods to get this work done. Before that let’s know about ordinal numbers. Ordinal number − In mathematics we say ordinal number as number which represents the position or original order of list items present in a sequence. Take an example of a list: [ 6, 8, 5, 3 ] so ordinal value of these number would be − The first element (6) has ordinal value 1. The second element (8) has ordinal value 2. The third element ... Read More

Jacobian matrix in PyTorch

Kalyan Mishra
Updated on 03-Oct-2023 15:13:34

192 Views

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. Jacobian Matrix We use Jacobian matrix to calculate relation between the input and output variable. Jacobian matrix has all the partial derivatives of vector valued function. We can use this matrix in various applications machine learning applications. Here are some of its usages − For analyzing the gradients and derivatives of functions in multivariable calculus. Solving differential equations of systems. Calculating inverse of vector-values functions. Analyzing stability of dynamic ... Read More

Iterating over rows and columns in Pandas DataFrame.

Kalyan Mishra
Updated on 03-Oct-2023 15:08:48

111 Views

In this article we will learn about pandas, DataFrame and how we can iterate over rows and columns in the pandas DataFrame using various methods. Iteration is a basic operation we do when we have tabular data containing rows and columns. To install the pandas in the system execute the command in cmd. pip install pandas Method 1. Using Iterrows() Method. Example import pandas as pd df = pd.DataFrame({'Name': ['Kalyan', 'Gungun', 'Sona', 'Ram'], 'Age': [21, 20, 23, 23], 'Roll': [12, 13, 14, 15], 'Game': ['Cricket', 'Lodu', 'Chess', ... Read More

Lumped Capacitance Analysis using Python

Dr Pankaj Dumka
Updated on 03-Oct-2023 13:14:11

135 Views

When an object at very high temperature is suddenly dropped in a cooler liquid and if it is assumed that the conductive resistance of the solid is very small in comparison to the surrounding convective resistance then the heat transfer analysis is called as lumped capacitance analysis (as shown in the figure given below). Here, we treat the system as a lump. In that case, we can assume that the rate of change of internal energy of lump will be equal to the heat interaction with the surrounding fluid. Mathematically, this can be written as − $$\mathrm{pcV\frac{\partial T}{\partial t} ... Read More

Advertisements