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 [9]:
# Load library
import numpy as np
In [10]:
# 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 [11]:
# Add two matrices
np.add(matrix_a, matrix_b)
Out[11]:
In [12]:
# Subtract two matrices
np.subtract(matrix_a, matrix_b)
Out[12]: