您的位置:首页 > 编程语言 > Python开发

[Python] Indexing An Array With Another Array with numpy

2017-12-18 21:32 357 查看

NumPy Reference: Indexing

Integer array indexing: Select array elements with another array

def indexing():
a = np.random.rand(5)
print(a)  #[ 0.71899463  0.50556877  0.8397599   0.37655158  0.88041567]
indices = np.array([1,1,2,3]) # access index of 1,1,2,3
print(a[indices])  #[ 0.50556877  0.50556877  0.8397599   0.37655158]

if __name__ == "__main__":
indexing()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: