Python - Vertical Concatenation in Matrix

Introduction:

In this tutorial, we are learning about Python - Vertical Concatenation in Matrix. It takes input as a Matrix form, which can perform string concatenation column-wise. It also handles the list variable's length. You can use list comprehension when you want to combine matrices vertically.

Example:

Now, we gave some examples of Vertical Concatenation in Matrix.

Give some examples of Vertical Concatenation of Matrix in Python:

Now, we give some examples of vertical concatenation of matrix in Python. The examples are given below -

Program code 1:

Here, we give an example of vertical concatenation in the matrix using loops. The code is written in Python, which is given below -

Output:

Now we compile the above code in Python, and after successful compilation, we run it. Then the output is given below -

The list of the string is: [['Hello', 'everyone'], ['good', 'morning'], ['Kolkata']]
The list of the string after column wise Concatenation is: ['HellogoodKolkata', 'everyonemorning']

Program code 2:

Now, we give another example of vertical concatenation in the matrix using packages. We use the zip_longest and join() function for the list's vertical concatenation. Here, we give three columns in the list, which performs column-wise concatenation. The code is written in Python, which is given below -

Output:

Now we compile the above code in Python, and after successful compilation, we run it. Then the output is given below -

The list of the string is: [['Hello', 'coders'], ['welcome', 'to'], ['JavaTpoint']]
The list of the string after column wise Concatenation is: ['HellowelcomeJavaTpoint', 'codersto'] 

Program code 3:

We give the last example of column-wise or vertical concatenation in the matrix using numpy libraries. Here, we use numpy.transpose() and numpy.ravel() function for performing the Column-wise concatenation. The code is written in Python, which is given below -

Output:

Now we compile the above code in Python, and after successful compilation, we run it. Then the output is given below -

The list of the string is: [['Hello', 'coders'], ['welcome', 'to'], ['JavaTpoint']]
The list of the string after column wise Concatenation is: ['HellowelcomeJavaTpoint', 'codersto']





Latest Courses