Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Mistake in linalg.eig() documentation #2721

Merged
merged 1 commit into from

2 participants

@abalkin

Proposed commit fixes a mistake in the formula currently written as dot(a[i,:], v[i]) = w[i] * v[:,i]. Here is the demonstration that it is incorrect:

a
array([[ 1.0093272 , 0.73994495, 1.50512547],
[ 0.73994495, 1.085796 , 1.33086593],
[ 1.50512547, 1.33086593, 1.39161296]])
w, v = eig(a)
i = 1
w[i] * v[:,i]
array([-0.20045129, 0.2535517 , -0.03350537])

but

dot(a[i,:], v[i])
-0.0096475519217383288

On the other hand,

dot(a[:,:], v[:,i])
array([-0.20045129, 0.2535517 , -0.03350537])

Explicit ':' slicing of a is redundant, but I think it makes documentation clearer by emphasizing the rank of a.

@abalkin

I don't think the Travis failure is caused by my changes.

2790ERROR: Test a special case for var
2791----------------------------------------------------------------------
2792Traceback (most recent call last):
2793 File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/numpy/ma/tests/test_core.py", line 2731, in test_varstd_specialcases
2794 _ = method(out=mout)
2795 File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/numpy/ma/core.py", line 4778, in std
2796 np.power(out, 0.5, out=out, casting='unsafe')
2797RuntimeWarning: invalid value encountered in power

@charris
Owner

Ping travisbot.

@charris charris closed this
@charris charris reopened this
@charris charris commented on the diff
numpy/linalg/linalg.py
@@ -946,7 +946,7 @@ def eig(a):
The number `w` is an eigenvalue of `a` if there exists a vector
`v` such that ``dot(a,v) = w * v``. Thus, the arrays `a`, `w`, and
- `v` satisfy the equations ``dot(a[i,:], v[i]) = w[i] * v[:,i]``
+ `v` satisfy the equations ``dot(a[:,:], v[:,i]) = w[i] * v[:,i]``
@charris Owner
charris added a note

Just dot(a, v[:, i] = w[i] * v[:, i] should do here. With broadcasting the simpler form dot(a, v) = v * w also works.but may be more confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@abalkin

I think I addressed this in my initial comment: "Explicit ':' slicing of a is redundant, but I think it makes documentation clearer by emphasizing the rank of a."

@charris charris merged commit 9b10a5f into numpy:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 9, 2012
  1. @abalkin
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  numpy/linalg/linalg.py
View
2  numpy/linalg/linalg.py
@@ -946,7 +946,7 @@ def eig(a):
The number `w` is an eigenvalue of `a` if there exists a vector
`v` such that ``dot(a,v) = w * v``. Thus, the arrays `a`, `w`, and
- `v` satisfy the equations ``dot(a[i,:], v[i]) = w[i] * v[:,i]``
+ `v` satisfy the equations ``dot(a[:,:], v[:,i]) = w[i] * v[:,i]``
@charris Owner
charris added a note

Just dot(a, v[:, i] = w[i] * v[:, i] should do here. With broadcasting the simpler form dot(a, v) = v * w also works.but may be more confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
for :math:`i \\in \\{0,...,M-1\\}`.
The array `v` of eigenvectors may not be of maximum rank, that is, some
Something went wrong with that request. Please try again.