Novice from Competent
Given the 2D array generated using the following code snippet:
———————————-
import numpy as np
x = np.random.normal(size=(10,10))
y = x[2:5,1:5]
———————————-
What is the shape of y?
- (4,5)
- (3,3)
- (3,4)
- (5,4)
- (4,3)
Expert from Competent
Suppose you had an array generated by the following code:
x = np.arange(25).reshape((5,5))
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24]])
Which of the following commands would give you the following array?
array([[ 1, 4],
[ 6, 9],
[21, 24]])
x[[0,1,4],[1,4]]
x[np.ix_([0,1,4],[1,4])]
x[np.meshgrid([0,1,4],[1,4])]
x[[0,1,4]][1,4]
x[[0,1,4]][[1,4],:]