Created
March 27, 2018 03:19
-
-
Save mintisan/aed0da31f6d68c0f0f480998c1cacdd1 to your computer and use it in GitHub Desktop.
Apply Operations To Elements with Lambda
This file contains 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
# Create matrix | |
matrix = np.array([[1, 2, 3], | |
[4, 5, 6], | |
[7, 8, 9]]) | |
# Create a function that adds 100 to something | |
add_100 = lambda i: i + 100 | |
# Create a vectorized function | |
vectorized_add_100 = np.vectorize(add_100) | |
# Apply function to all elements in matrix | |
vectorized_add_100(matrix) | |
# array([[101, 102, 103], | |
# [104, 105, 106], | |
# [107, 108, 109]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment