0

I have an array of arrays and I need to get the amax for each row.

[[-1.53286755e-02  2.93346513e-02 -7.66370669e-02 -2.19948404e-02]
 [-1.25247389e-02  1.43674174e-02 -6.83528483e-02 -1.07235834e-02]
 [-1.51151344e-02  3.38465981e-02 -7.61222318e-02 -1.83092393e-02]
 [ 4.46393713e-03  1.87037606e-02 -6.09790049e-02 -1.94273535e-02]
 [-1.64875668e-02  2.76340060e-02 -6.66617230e-02 -1.33732818e-02]
 [-3.99522949e-04  1.20752566e-02 -6.02767840e-02 -1.47377616e-02]
 [-6.86090253e-03  2.22653989e-02 -6.96686357e-02 -3.29462299e-03]
 [ 3.94986942e-03  3.54665779e-02 -7.09369779e-02 -6.11725636e-03]
 [ 3.49313393e-03  2.98086051e-02 -7.18421638e-02 -5.45137282e-03]
 [ 1.18993018e-02  2.50301771e-02 -6.93574101e-02  2.55537452e-04]
 [ 8.19707289e-04  6.50310218e-02 -1.46873474e-01  7.08404928e-03]
...

My array looks like that and I want to do np.amax on it to get the maximum value per row.

I tried best_q = np.amax(amax[0]), but this simply returns the highest value in the entire array.

I'd like to do this vectorized somehow to save processing time.

2 Answers 2

3

Check with you need to pass the correct index to aggregate, here is axis=1

np.max(a,axis = 1) # np.amax(a,axis=1)

Out[199]: 
array([0.09640129, 0.09834351, 0.09433366, 0.9100043 , 0.9104525 ,
       0.90350811])
Sign up to request clarification or add additional context in comments.

Comments

1

You need to add "axis" param to amax to get max over an axis

np.amax(a, axis=1) or np.amax(a, axis=0)

check: https://docs.scipy.org/doc/numpy/reference/generated/numpy.amax.html

1 Comment

it's simple: all horizontal elements, or all vertical elements. like X-axis and Y-axis

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.