1.从二维矩阵中每行选出特定的index对应的位置的值
from mxnet import nd
in_num=5
ex_num=[0,2,1,3,1]
p=nd.random.randint(5, 100,shape=(in_num,6))
p,p.pick(nd.array(ex_num))
(
[[81 26 9 85 90 37]
[95 96 68 75 17 44]
[66 47 21 17 51 26]
[47 64 8 5 35 47]
[43 70 25 29 93 92]]
<NDArray 5x6 @cpu(0)>,
[81 68 47 5 70]
<NDArray 5 @cpu(0)>)
2.axis=1/0的问题
p=nd.random.randint(1, 5,shape=(3,2))
p,
p.sum(axis=1,keepdims=True)
,p.sum(axis=0)
[[2 4]
[1 2]
[4 2]]
<NDArray 3x2 @cpu(0)>,
[[6]
[3]
[6]]
<NDArray 3x1 @cpu(0)>,
[7 8]
<NDArray 2 @cpu(0)>)