Skip to content

Instantly share code, notes, and snippets.

@dboyliao
Created March 17, 2016 10:18
Show Gist options
  • Save dboyliao/e8fef3f604ba3900549b to your computer and use it in GitHub Desktop.
Save dboyliao/e8fef3f604ba3900549b to your computer and use it in GitHub Desktop.
from __future__ import print_function
import numpy as np
m = np.array([[1, 2], [3, 4]])
print("m**2: ")
print(m**2)
print("matrix_power:")
print(np.linalg.matrix_power(m, 2))
# you can apply ** operation on a non-square matrix, which is impossible for a non-square matrix to do
# so if ** is to raise a matrix to upper power.
m = np.array([[1, 2, 3], [4, 5, 6]])
print("m**2 (non-square):")
print(m**2)
# np.linalg.matrix_power(m, 2) # ValueError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment