码迷,mamicode.com
首页 > 其他好文 > 详细

numpy ndarray 返回 index 问题

时间:2017-07-19 14:44:44      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:round   rate   span   color   nbsp   ack   .sh   pytho   dex   

经常遇到需要返回满足条件的index。 python中没有which函数,但有列表推导式, 可以实现类似功能

y= np.array([3,2,5,20])

y
Out[131]: array([ 3, 2, 5, 20])

[x for x in range(y.shape[0]) if y[x]>3]
Out[129]: [2, 3]    输出满足条件的索引号

 

In [23]: {i:el for i,el in enumerate(["one","two","three"])}
Out[23]: {0: ‘one‘, 1: ‘two‘, 2: ‘three‘}

numpy ndarray 返回 index 问题

标签:round   rate   span   color   nbsp   ack   .sh   pytho   dex   

原文地址:http://www.cnblogs.com/xinping-study/p/7205112.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!