1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| x = np.array([[1,2],[3,4],[5,6]]) y = x[[0,1,2],[0,1,0]] print(y)
x = np.array([[0,1,2],[3,4,5],[6,7,8],[9,10,11]]) print (x) print ('\n') rows = np.array([[0,0],[3,3]]) cols = np.array([[0,2],[0,2]]) y = x[rows,cols] print (y)
a = np.array([[1,2,3], [4,5,6],[7,8,9]]) b = a[1:3, 1:3] c = a[1:3,[1,2]] d = a[...,1:] print(b) print(c) print(d)
x = np.array([[0,1,2],[3,4,5],[6,7,8],[9,10,11]]) print (x[x>5])
x = np.arange(32).reshape((8,4)) print (x[[4,2,1,7]])
x=np.arange(32).reshape((8,4)) print (x[np.ix_([1,5,7,2],[0,3,1,2])])
|