Let me give you an example of who we use the t[t_index] syntax to help you understand how it works. I sometimes use integer arrays to represent images using a color pallet. Each of 256 colors, rgb values, are stored in a pallet array that has shape (256, 3). The image is stored as an array of (1000, 1000) integers between 0 and 255, or indices into the pallet array. If I want to create an rgb image, for example for display purpose i do rgbimage = pallet[image] to create an rgb image which is (1000, 1000, 3).
update:
I see that you've updated your question in include argsort, maybe you're trying to do something similar tho this question. For a 2d array, the short version looks like this:
s = np.random.random((54, 54))
t = np.random.random((54, 54))
axis = 0
t_index = s.argsort(axis)
idx = np.ogrid[:t.shape[0], :t.shape[1]]
idx[axis] = t_index
t_sort = t[idx]
I was looking for a good explanation of how this works, but I can't seem to find a good one. If anyone has a good reference for how ogrid works, or how broadcasting in numpy indexing works please leave a note in the comments. I'll write a short explanation which should help.
Lets say t is a 2d array and I want to pick out 2 elements from each column, I would do the following:
t = np.arange((12)).reshape(3, 4)
print t
# [[ 0, 1, 2, 3],
# [ 4, 5, 6, 7],
# [ 8, 9, 10, 11]]
print t[[0, 3], :]
# [[ 0 1 2 3]
# [ 8 9 10 11]]
Now imagine I want different elements from each row, I might try:
row_index = [[0, 2],
[0, 2],
[1, 2],
[0, 1]]
t[row_index]
# Which in python is the same as
t[row_index, :]
But that will not work. This behavior shouldn't be surprising because the : means every column. In the previous example we got every column for 0, and every column for 2. What we really want is:
row_index = [[0, 2],
[0, 2],
[1, 2],
[0, 1]]
column_index = [[0, 0],
[1, 1],
[2, 2],
[3, 3]]
t[row_index, column_index]
Numpy also lets us cheat and use the following because the values are just repeated:
column_index = [[0],
[1],
[2],
[3]]
Read about broadcasting to understand this better. I hope this explanation is helpful.
t[i, j]instead oft[i][j].sortandargsortan array no matter what you are trying to do. My guess is that what you want to do is:t_index = np.argsort(adj, axis=0); mask = (t_index < adj.shape[0] - 5); adj[mask] = 0