Created
January 9, 2017 02:20
-
-
Save akhalsa/5a1bd3ae8a0a1e6674a8d7a827ac04b9 to your computer and use it in GitHub Desktop.
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 | |
# Create the following rank 2 array with shape (3, 4) | |
# [[ 1 2 3 4] | |
# [ 5 6 7 8] | |
# [ 9 10 11 12]] | |
a = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]]) | |
# Use slicing to pull out the subarray consisting of the first 2 rows | |
# and columns 1 and 2; b is the following array of shape (2, 2): | |
# [[2 3] | |
# [6 7]] | |
b = a[:2, 1:3] | |
# A slice of an array is a view into the same data, so modifying it | |
# will modify the original array. | |
print a[0, 1] # Prints "2" | |
b[0, 0] = 77 # b[0, 0] is the same piece of data as a[0, 1] | |
print a[0, 1] # Prints "77" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment