Created
January 2, 2017 19:25
-
-
Save yunwilliamyu/b768f63178de7aad8325847580e4740d to your computer and use it in GitHub Desktop.
Numpy 1.11.0 vs 1.8.2 matrix nonzero fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
A = np.matrix([[1, 2], [3, 4]]) | |
A[0,:].nonzero() # Returns (matrix([[0, 0]]), matrix([[0, 1]])) if np.__version__ == "1.8.2" | |
# Returns (array([0, 0]), array([0, 1])) if np.__version__ == "1.11.0" | |
np.asarray(A[0,:]).nonzero() # Returns (array([0, 0]), array([0, 1])) for both versions, so is backwards compatible |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment