Title: Transpose A Vector Or Matrix
Slug: transpose_a_vector_or_matrix
Summary: How to transpose a vector or matrix in Python.
Date: 2017-09-02 12:00
Category: Machine Learning
Tags: Vectors Matrices Arrays
Authors: Chris Albon

Preliminaries


In [13]:
# Load library
import numpy as np

Create Vector


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

Create Matrix


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

Transpose Vector


In [16]:
# Tranpose vector
vector.T


Out[16]:
array([1, 2, 3, 4, 5, 6])

Transpose Matrix


In [17]:
# Transpose matrix
matrix.T


Out[17]:
array([[1, 4, 7],
       [2, 5, 8],
       [3, 6, 9]])