First your a expression is missing []
In [231]: a=np.array([[5, 1, 10], [2, 3, 4]]) # add extra []
In [232]: a
Out[232]:
array([[ 5, 1, 10],
[ 2, 3, 4]])
A list comprehension is the easiest way to produce the shown list
In [233]: [[(n,i+1) for i,n in enumerate(row)] for row in a]
Out[233]: [[(5, 1), (1, 2), (10, 3)], [(2, 1), (3, 2), (4, 3)]]
I could do it by concatenating np.arange(1,4) as well, but the inner elements wouldn't be tuples. I'd have to use a structured array to get that kind of display.
This is the kind of 3d array we'd get with a concatenate:
In [234]: np.array(_)
Out[234]:
array([[[ 5, 1],
[ 1, 2],
[10, 3]],
[[ 2, 1],
[ 3, 2],
[ 4, 3]]])
A structured array with the same tolist() output:
In [244]: alist=[[(n,i+1) for i,n in enumerate(row)] for row in a]
In [245]: a3=np.array(alist, dtype='i,i')
In [246]: a3
Out[246]:
array([[( 5, 1), ( 1, 2), (10, 3)],
[( 2, 1), ( 3, 2), ( 4, 3)]],
dtype=[('f0', '<i4'), ('f1', '<i4')])
Building direct:
In [254]: a2=np.zeros((a.shape[0],a.shape[1],2),a.dtype)
In [255]: a2[:,:,0]=a
In [256]: a2[:,:,1]=np.arange(1,4)
In [257]: a2
Out[257]:
array([[[ 5, 1],
[ 1, 2],
[10, 3]],
[[ 2, 1],
[ 3, 2],
[ 4, 3]]])
or for the structured case:
In [258]: a2=np.zeros((a.shape[0],a.shape[1]),dtype='i,i')
In [259]: a2['f0']=a
In [260]: a2['f1']=np.arange(1,4)
Same construction, but with the sorted values as described in the edits:
In [281]: idx=np.argsort(-a,axis=1)
In [282]: a1 = -np.sort(-a,1)
In [283]: a2=np.zeros((a.shape[0],a.shape[1]),dtype='i,i')
In [285]: a2['f0']=a1
In [286]: a2['f1']=idx
In [287]: a2
Out[287]:
array([[(10, 2), ( 5, 0), ( 1, 1)],
[( 4, 2), ( 3, 1), ( 2, 0)]],
dtype=[('f0', '<i4'), ('f1', '<i4')])