v Transpose A Vector Or Matrix - Machine Learning

Transpose A Vector Or Matrix

Preliminaries

# Load library
import numpy as np

Create Vector

# Create vector
vector = np.array([1, 2, 3, 4, 5, 6])

Create Matrix

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

Transpose Vector

# Tranpose vector
vector.T
array([1, 2, 3, 4, 5, 6])

Transpose Matrix

# Transpose matrix
matrix.T
array([[1, 4, 7],
       [2, 5, 8],
       [3, 6, 9]])