Skip to content

Commit d5e440e

Browse files
committed
Merge pull request #478 from Axelrod-Python/475
Add line to suppress runtime warning from numpy
2 parents 2681380 + 4c30b4f commit d5e440e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

axelrod/eigen.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@
1010

1111
def normalise(nvec):
1212
"""Normalises the given numpy array."""
13-
return nvec / numpy.sqrt(numpy.dot(nvec, nvec))
13+
with numpy.errstate(invalid='ignore'):
14+
result = nvec / numpy.sqrt(numpy.dot(nvec, nvec))
15+
return result
16+
1417

1518
def squared_error(vector_1, vector_2):
1619
"""Computes the squared error between two numpy arrays."""
1720
diff = vector_1 - vector_2
1821
s = numpy.dot(diff, diff)
1922
return numpy.sqrt(s)
2023

24+
2125
def power_iteration(mat, initial):
2226
"""
2327
Generator of successive approximations.
@@ -39,6 +43,7 @@ def power_iteration(mat, initial):
3943
vec = normalise(numpy.dot(mat, vec))
4044
yield vec
4145

46+
4247
def principal_eigenvector(mat, maximum_iterations=None, max_error=1e-8):
4348
"""
4449
Computes the (normalised) principal eigenvector of the given matrix.

0 commit comments

Comments
 (0)