【发布时间】:2016-05-29 09:01:48
【问题描述】:
这是我的问题。
这里有一些背景介绍:
- a 是一个二维 numpy 数组,大小为 (50,50)
- a 中的一些元素是 np.NAN,其他元素有其有限值。
我的目标
获取a百分位范围(70, 80)内每个元素的数组索引
我的尝试
-
过滤 a
中的 np.NANa_noNaN = np.array([0,]) for i in range(0,a.shape[0],1): for j in range(0,a.shape[1],1): if (np.isnan(a[i,j]) == False): a_noNaN = np.append(a_noNaN,a[i,j]) a_noNaN = a_noNaN[1:] ## the first element "0" is redundant -
对数据进行排序并确定取值范围
a_noNaN_sort = np.sort(a_noNaN) a_70 = np.percentile(a_noNaN, 70) a_80 = np.percentile(a_noNaN, 80) -
获取该值范围内的数组索引
k = 0 indice = np.array([(i, j) for i in xrange(a.shape[0]) for j in xrange(a.shape[1])]) indice_in = np.zeros_like(indice) for t in range(0,indice.shape[0],1): for i in range(a.shape[0]): for j in range(a.shape[1]): if ((a[i,j]<a_80)& ((a[i,j]>a_70))): indice_in[t] = indice[t]
我不知道我的方法是对是错。
我可以使用任何更简单的功能来完成工作吗?
任何建议将不胜感激!ヽ(✿゚▽゚)ノ
【问题讨论】:
标签: python arrays python-2.7 numpy statistics