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
Server Side Programming Articles
Page 124 of 2109
Python Program to Display Upper Triangular Matrix
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 MorePython Program to Recursively Linearly Search an Element in an Array
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 MorePython Program To Find the Trace and Normal of a given Matrix
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 MorePython Program to Multiply to Matrix Using Multi-dimensional Arrays
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 MorePython Program to Add Two Matrix Using Multi-dimensional Array
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 MorePython Program to Interchange Elements of First and Last in a Matrix Across Columns
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 MorePython Program to Interchange Elements of First and Last in a Matrix Across Rows
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 MoreHow do I create a constant in Python?
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 MoreHow to display notnull rows and columns in a Python dataframe?
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 MoreHow to display most frequent value in a Pandas series?
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