finding the max of a column in an array

前端 未结 2 998
猫巷女王i
猫巷女王i 2021-01-18 19:59
def maxvalues():        
for n in range(1,15):
    dummy=[]
    for k in range(len(MotionsAndMoorings)):
        dummy.append(MotionsAndMoorings[k][n])
    max(dummy         


        
2条回答
  •  青春惊慌失措
    2021-01-18 20:39

    An example with a random input array, showing that you can take the max in either axis easily with one command.

    import numpy as np
    
    aa= np.random.random([4,3]) 
    print aa
    print
    print np.max(aa,axis=0)
    print
    print np.max(aa,axis=1)
    

    Output:

    [[ 0.51972266  0.35930957  0.60381998]
     [ 0.34577217  0.27908173  0.52146593]
     [ 0.12101346  0.52268843  0.41704152]
     [ 0.24181773  0.40747905  0.14980534]]
    
    [ 0.51972266  0.52268843  0.60381998]
    
    [ 0.60381998  0.52146593  0.52268843  0.40747905]
    

提交回复
热议问题