【发布时间】:2017-09-16 19:35:41
【问题描述】:
我有以下三个数据集。
- 2 3
- 4 5
- 6 6
- 5 7
- 7 4
- 9 9
- 1 8
- 2 3
- 3 2
基本上,我想创建一个列,其中元素将是第二列相应元素的中位数。每个集合的第二列的第一个元素是 (3,7,8) 和中位数 = 7,数据集的第二列的第二个元素是 (5,4,3) 和中位数 = 4 和第三个元素数据集的第二列是 (6,9,2) 和中位数 =6。所以我希望我的输出是一个像 [(7,4,6)] 这样的 numpy 数组。
我尝试了以下方法:
import numpy as np
filelist=[]
for i in range (1,4):
filelist.append("/Users/Hrihaan/Desktop/A_%s.txt" %i)
for fname in filelist:
data=np.loadtxt(fname)
x=data[:,1]
for j in range (0,3):
y=np.median(x[j,1]) # tried this method and thought would get the arrays i want (3,7,8) , (5,4,3) and (6,9,2) and their medians
print(y)
收到以下错误:(IndexError: too many indices for array)
任何建议都意义重大。
【问题讨论】: