v Reshape An Array - Machine Learning

Reshape An Array

Preliminaries

# Load library
import numpy as np

Create Array

# Create a 4x3 matrix
matrix = np.array([[1, 2, 3],
                   [4, 5, 6],
                   [7, 8, 9],
                   [10, 11, 12]])

Reshape Array

# Reshape matrix into 2x6 matrix
matrix.reshape(2, 6)
array([[ 1,  2,  3,  4,  5,  6],
       [ 7,  8,  9, 10, 11, 12]])