参考:
https://zhuanlan.zhihu.com/p/589656733
import numpy as np
n0 = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
# 方便找到满足条件的值
coords_where = np.where(n0 > 5) # n0找出所有大于5的元素的位置
print(coords_where)
'''
out:
(array([1, 2, 2, 2], dtype=int64), array([2, 0, 1, 2], dtype=int64))
'''
val0_from_coords_where = n0[coords_where]
print(val0_from_coords_where)
'''
out:
[6 7 8 9]
'''
import numpy as np
n0 = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
# 用于返回满足条件的坐标索引
coords_argwhere = np.argwhere(n0 > 5) # n0找出所有大于5的元素的位置
print(coords_argwhere)
'''
out:
[[1 2]
[2 0] [2 1] [2 2]] '''
from numpy import argwhere
import numpy as np
modulation_onehot = np.array([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0])
int(argwhere(modulation_onehot == 1))