Title: Adding And Subtracting Matrices
Slug: adding_and_subtracting_matrices
Summary: How to add and subtract matrices in Python.
Date: 2017-09-03 12:00
Category: Machine Learning
Tags: Vectors Matrices Arrays
Authors: Chris Albon
In [13]:
# Load library
import numpy as np
In [14]:
# Create matrix
matrix_a = np.array([[1, 1, 1],
[1, 1, 1],
[1, 1, 2]])
# Create matrix
matrix_b = np.array([[1, 3, 1],
[1, 3, 1],
[1, 3, 8]])
In [15]:
# Add two matrices
np.add(matrix_a, matrix_b)
Out[15]:
In [16]:
# Subtract two matrices
np.subtract(matrix_a, matrix_b)
Out[16]: