How to Flatten a Matrix?
0

How to Flatten a Matrix?

This recipe helps you Flatten a Matrix
In [1]:
## How to Flatten a Matrix
def Kickstarter_Example_10():
    print()
    print(format('How to Flatten a Matrix', '*^72'))

    #load library
    import numpy as np

    # Create matrix
    matrixA = np.array([[1, 2, 3, 23],
                       [4, 5, 6, 25],
                       [7, 8, 9, 28],
                       [10, 11, 12, 41]])

    matrixB = np.array([[2, 3, 4],
                       [5, 6, 9],
                       [7, 8, 1]])

    # Return a flatten matrix
    print(); print(matrixA.flatten())
    print(); print(matrixB.flatten())
Kickstarter_Example_10()
************************How to Flatten a Matrix*************************

[ 1  2  3 23  4  5  6 25  7  8  9 28 10 11 12 41]

[2 3 4 5 6 9 7 8 1]