# 如何取出每列中包含最大值的矩阵？-问答-阿里云开发者社区-阿里云

## 如何取出每列中包含最大值的矩阵？

x= [1,2,4,3] , y= [7,8,6,5] , z= [12,10,11,9]

alldata=[];

alldata.append([x]);

alldata.append([y]);

alldata.append([z]);

for elem in alldata:

``````xarr=np.array(elem)
rowmax=xarr.argmax()
ind= alldata.index(elem)
maxcorr.append(alldata[ind][0][rowmax])
``````

for elem in alldata:

``````xarr=np.array(elem)
rowmin=xarr.argmin()
ind= alldata.index(elem)
maxcorr.append(alldata[ind][0][rowmin])``````

XMAX，Y，Z，X，YMAX，Z2，X3，Y3，ZMAX，XMIN，Y4，Z4，.....

x=np.transpose(x);

y=np.transpose(y);

z=np.transpose(z);

mydata=[]
mydata.append(x)
mydata.append(y)
mydata.append(z)

mydata=np.array(mydata)

casename=['Xmax', 'Y', 'Z', ,'Xmin', 'Y', 'Z', 'X', 'Ymax', 'Z', 'X', 'Ymin', 'Z', 'X', 'Y', 'Zmax','X', 'Y', 'Zmin']
mydata=np.array(mydata).reshape(-1, len(casename))
df = pd.DataFrame(mydata, index=Filenames, columns=casename)

[4,5,11,1,7,12,2,8,10,3,5,9,1,7,12,3,5,9]

Python

• 一码平川MACHEL
2019-07-17 23:26:44

xmax,y,z,x2,ymax,z2,x3,y3,zmax,xmin,y4,z4,.....

df = pd.DataFrame(list(zip(x, y, z)), columns=['x', 'y', 'z'])
mylist = []
for i in df.columns:

``mylist+=(list(df.loc[df[i].argmax()]))``

for i in df.columns:

``mylist+=(list(df.loc[df[i].argmin()]))``

Out: [4, 6, 11, 2, 8, 10, 1, 7, 12, 1, 7, 12, 3, 5, 9, 3, 5, 9]

0 0

+ 订阅