I have the following three data sets.
- 2 3
- 4 5
- 6 6
- 5 7
- 7 4
- 9 9
- 1 8
- 2 3
- 3 2
Basically, i want to create a column where the elements will be the median of the corresponding elements of the second column. The first elements of the second column for each of the sets are (3,7,8) and median=7, second elements of the second column of the data sets are (5,4,3) and median=4 and third elements of the second column of data sets are (6,9,2) and median =6. So I want my output to be a numpy array like [(7,4,6)].
I tried the following approach:
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)
Received the following error : (IndexError: too many indices for array)
Any suggestion would mean a lot.