Found 10476 Articles for Python

Python Program to Find Common Elements in Two Arrays

Gireesha Devara
Updated on 15-May-2023 16:55:25

7K+ Views

An array is a data structure consisting of a collection of elements of same data type, and each element is identified by an index. [2, 4, 0, 5, 8] 0 1 2 3 4 The integers 2, 4, 0, 5, 8 are the array elements and 0, 1, 2, 3, 4 are the respective index values of the array elements. In The article below, we will discuss the python program to find common elements between two arrays. Input Output Scenarios Assuming we have two arrays A and B. And the resultant ... Read More

Python Program To Determine If a Given Matrix is a Sparse Matrix

Gireesha Devara
Updated on 15-May-2023 16:53:11

627 Views

A matrix is a rectangular array where the set of numbers arranged in rows and columns. And it is called as an m X n matrix where m and n are the dimensions. If a matrix contains a very less number of non-zero elements compared to the zero elements then it is called a sparse matrix. [0, 0, 3, 0, 0] [0, 1, 0, 0, 6] [1, 0, 0, 9, 0] [0, 0, 2, 0, 0] The above matrix is 4X5 matrix here most of the numbers are zero. Only a few elements are non-zero so that we can ... Read More

Python Program to Display Upper Triangular Matrix

Gireesha Devara
Updated on 15-May-2023 16:51:03

2K+ Views

A matrix is a two-dimensional array of many numbers arranged in rows and columns. A square matrix (whose rows and columns has same number of elements) has two diagonals. One is the Primary diagonal - located from the top left corner to the bottom right corner of a square matrix. And the second one 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. [1, 3, 4] [0, 5, 6] [0, ... Read More

Python Program to Recursively Linearly Search an Element in an Array

Gireesha Devara
Updated on 15-May-2023 16:39:34

2K+ 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, while using a recusive function we need to use any loop to generate the iterations. The below syntax demonistrates the working of a simple recursion function. def rerecursiveFun(): Statements ... rerecursiveFun() ... rerecursiveFun Linear Search of an Element ... Read More

Python Program to Multiply two Matrices by Passing Matrix to a Function

Gireesha Devara
Updated on 15-May-2023 16:38:14

307 Views

A matrix is a two-dimensional array of many numbers arranged in rows and columns. And it is called as m X n matrix where m and n are the dimensions. In general, the multiplication of two matrices can be possible only if the number of columns in the first matrix is equal to the number of rows in the second matrix. Input Output Scenarios Assuming we have two input matrices A and B having 3X3 rows and columns. Then the resultant matrix will also have 3 rows and 3 column. [a, b, c] [j, k, l] [(a*j+b*m+c*p), (a*k+b*n+c*q), (a*l+b*o+c*r)] [d, ... Read More

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

Gireesha Devara
Updated on 15-May-2023 16:35:50

2K+ 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 can be possible only for a square matrix (i.e., the matrix ... Read More

Python Program to Multiply to Matrix Using Multi-dimensional Arrays

Gireesha Devara
Updated on 15-May-2023 16:34:12

463 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 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. In general, Matrix multiplication can be done by multiplying the rows of the first matrix by the column of the second matrix. Here, the number of columns of the first matrix should be equal to the number of rows of the second matrix. Input Output Scenarios Assuming ... Read More

Python Program to Add Two Matrix Using Multi-dimensional Array

Gireesha Devara
Updated on 15-May-2023 16:32:53

1K+ Views

A matrix is a two-dimensional array of many numbers arranged in rows and columns. The addition of two matrices is a process of adding corresponding elements of two matrices and placing the sum in corresponding position of the resultant matrix. And this can be possible, only if both the matrices have an equal number of rows and columns. In Python multidimensional arrays are created by using lists or NumPy arrays. The list data structure can accept lists as elements so that we can easily create matrice. Also, the Numpy module provides numerous methods to work with multidimensional arrays. ... Read More

Python Program to Interchange the Diagonals of a matrix using predefined methods

Gireesha Devara
Updated on 15-May-2023 16:31:21

307 Views

The diagonals are nothing but crosswise elements of a matrix. A square matrix has two diagonals. One is the Primary diagonal - located from the top left corner to the bottom right corner of a square matrix. And the second one is the Secondary diagonal - located from the top right to the bottom left corner. Interchange the diagonals is nothing but changing the primary and secondary diagonal elements of a matrix. See the below scenarios to understand it briefly Input Output Scenarios Assume we have a square matrix. And output matrix will be the resultant matrix ... Read More

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

Gireesha Devara
Updated on 15-May-2023 16:29:12

263 Views

A matrix is a two-dimensional array of many numbers arranged in rows and columns form. Python does not have any data type to represent a matrix, but we can use a nested list or NumPy array as a matrix. See the below input output scenarios to understand how to interchange the first and last column elements of a matrix. Input Output Scenarios Assume we have a 3X3 matrix represented using a list of lists. And output matrix will be the resultant matrix whose first and last column elements are interchanged. Input matrix: [1, 3, 4] [4, 5, 6] [7, ... Read More

Advertisements