Found 10784 Articles for Python

Python Program to Append an Element Into an Array

Gireesha Devara
Updated on 15-May-2023 17:08:11

1K+ Views

An array is a collection of elements of same data type, and each element in the array is identified by an index value. It is a simplest data structure and we can easily add or remove elements. Arrays in Python Python does not have a specific data structure to represent arrays. Here, we can use List an array. [9, 3, 1, 6, 9] We can use array or NumPy module to work with arrays in python. array('i', [1, 2, 3, 4]) The above array is the integer Array which is defined by the array module. In ... Read More

Python Program to Iterate Over an Array

Gireesha Devara
Updated on 15-May-2023 17:05:59

322 Views

An array is a data structure consisting of a set of elements (values) of the same data type, each element is identified by an index value. And the elements can be directly accessed by using their index numbers. Arrays in Python Python does not have a native array data structure. Instead, we can use the list data structure, NumPy, or array modules. Here we will use list an array − [10, 4, 11, 76, 99] 0 1 2 3 4 The ... Read More

Python Program to Find Common Elements in Two Arrays

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

5K+ 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

396 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

1K+ 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

1K+ 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

175 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

1K+ 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

223 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

649 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

Advertisements