Server Side Programming Articles

Page 124 of 2109

Python Program to Display Upper Triangular Matrix

Gireesha Devara
Gireesha Devara
Updated on 27-Mar-2026 3K+ Views

A matrix is a two-dimensional array of numbers arranged in rows and columns. A square matrix (whose rows and columns have the same number of elements) has two diagonals. One is the primary diagonal − located from the top left corner to the bottom right corner. The second is the secondary diagonal − located from the top right to the bottom left corner. For a square matrix, if all the elements below the primary diagonal are zero, then it is called the Upper Triangular Matrix. # Example of upper triangular matrix matrix = [[1, 3, 4], ...

Read More

Python Program to Recursively Linearly Search an Element in an Array

Gireesha Devara
Gireesha Devara
Updated on 27-Mar-2026 3K+ Views

Linear search is the simplest method of searching for an element in an array. It is a sequential searching algorithm that starts from one end and checks every element of the array until the desired element is found. Recursion means a function that calls itself. When using a recursive function, we don't need any loop to generate iterations. The below syntax demonstrates the working of a simple recursion function ? def recursiveFunction(): # Statements # ... recursiveFunction() # ...

Read More

Python Program To Find the Trace and Normal of a given Matrix

Gireesha Devara
Gireesha Devara
Updated on 27-Mar-2026 3K+ Views

A matrix is defined as a set of numbers arranged in rows and columns. A matrix with m rows and n columns is called an m X n matrix and m and n are called its dimensions. A matrix is a two-dimensional array, which is created by using lists or NumPy arrays in Python. The Trace of a Matrix The trace of a matrix is defined as the sum of its diagonal elements (i.e., elements from upper left to lower right). Calculating the trace of a matrix is possible only for a square matrix (i.e., the matrix whose ...

Read More

Python Program to Multiply to Matrix Using Multi-dimensional Arrays

Gireesha Devara
Gireesha Devara
Updated on 27-Mar-2026 622 Views

A matrix is a set of numbers arranged in rows and columns. A matrix with m rows and n columns is called an m × n matrix and m and n are called its dimensions. In Python, matrices can be created using lists or NumPy arrays. Matrix multiplication can be done in two ways: standard matrix multiplication (dot product) where the number of columns in the first matrix must equal the number of rows in the second matrix, and element-wise multiplication where matrices must have the same dimensions. Matrix Multiplication Types For standard matrix multiplication, if we ...

Read More

Python Program to Add Two Matrix Using Multi-dimensional Array

Gireesha Devara
Gireesha Devara
Updated on 27-Mar-2026 1K+ Views

A matrix is a two-dimensional array of numbers arranged in rows and columns. The addition of two matrices involves adding corresponding elements and placing the sum in the corresponding position of the resultant matrix. This operation is only possible when both matrices have equal dimensions. In Python, multidimensional arrays are created using lists or NumPy arrays. The list data structure can accept lists as elements, making it easy to create matrices. The NumPy module provides numerous methods to work efficiently with multidimensional arrays. Matrix Addition Formula For two matrices A and B, the addition follows this pattern ...

Read More

Python Program to Interchange Elements of First and Last in a Matrix Across Columns

Gireesha Devara
Gireesha Devara
Updated on 27-Mar-2026 366 Views

A matrix is a two-dimensional array of numbers arranged in rows and columns. Python doesn't have a built-in matrix data type, but we can use nested lists or NumPy arrays to represent matrices. In this tutorial, we'll learn how to interchange the first and last column elements in each row of a matrix using different approaches. Input Output Scenarios Let's understand the problem with examples. For a 3×3 matrix, we swap the first and last elements of each row ? # Example 1: Square matrix original = [ [1, 3, 4], ...

Read More

Python Program to Interchange Elements of First and Last in a Matrix Across Rows

Gireesha Devara
Gireesha Devara
Updated on 27-Mar-2026 250 Views

A matrix is a set of numbers arranged in rows and columns format. In Python, a matrix can be created using nested lists or NumPy arrays. This tutorial demonstrates how to interchange the first and last rows of a matrix. Input Output Scenarios Let's look at examples of interchanging first and last rows in different matrices ? Input matrix: [1, 2, 3] [4, 5, 6] [7, 8, 9] Output matrix: [7, 8, 9] [4, 5, 6] [1, 2, 3] For matrices with unequal row lengths ? Input matrix: ...

Read More

How do I create a constant in Python?

Gireesha Devara
Gireesha Devara
Updated on 27-Mar-2026 2K+ Views

In Python, there's no built-in data type for constants like other programming languages. However, Python follows naming conventions and provides several approaches to create constants that signal to other developers that a value shouldn't be changed. Built-in Constants in Python Python has six built-in constants: False, True, None, NotImplemented, Ellipsis (...), and __debug__. These cannot be reassigned ? # Trying to reassign a built-in constant raises SyntaxError try: False = 100 except SyntaxError as e: print(f"Error: {e}") File "", line 2 ...

Read More

How to display notnull rows and columns in a Python dataframe?

Manthan Ghasadiya
Manthan Ghasadiya
Updated on 27-Mar-2026 7K+ Views

In this tutorial, we will learn how to display notnull rows and columns in a Python dataframe using the Pandas library. A dataframe is a two-dimensional labeled data structure that can hold multiple columns of potentially different data types such as integer, float, string, etc. Using dropna() Method The dropna() method returns a dataframe with all rows and columns containing null values removed from the original dataframe ? Syntax df.dropna() Example In this example, we create a sample dataframe with some null values and use dropna() to remove rows containing any null ...

Read More

How to display most frequent value in a Pandas series?

Manthan Ghasadiya
Manthan Ghasadiya
Updated on 27-Mar-2026 9K+ Views

In this tutorial, we will learn how to display the most frequent value in a Pandas series. A Pandas Series is a one-dimensional labeled data structure that can hold different data types like integers, floats, and strings. The most frequent value is also known as the mode of the data. Using value_counts() Method The value_counts() method returns a Series with counts of each unique value sorted in descending order. The most frequent value appears first. Syntax counts = series.value_counts() most_frequent = counts.index[0] Example with Numbers Let's find the most frequent number in ...

Read More
Showing 1231–1240 of 21,090 articles
« Prev 1 122 123 124 125 126 2109 Next »
Advertisements