gis_grad_student
gis_grad_student

Reputation: 184

Infinity norm for each row of numpy array

I have a numpy array:

t1 = np.arange(12).reshape(3,4)

I need to find the L-infinity norm of each row of the array and return the row index with the minimum L-infinity norm.

I am trying this to find the norm of each row:

rest1 = LA.norm(t1, ord='inf', axis=1)

But I keep getting the following error:

raise ValueError(f"Invalid norm order '{ord}' for vectors") ValueError: Invalid norm order 'inf' for vectors

Can you all please suggest how I can do that? Thanks a lot!

Upvotes: 0

Views: 1376

Answers (1)

Daniel Konstantinov
Daniel Konstantinov

Reputation: 411

import numpy as np
t1 = np.arange(12).reshape(3,4)
rest1 = np.linalg.norm(t1, ord=np.inf, axis=1)
# >>> array([ 3.,  7., 11.])

Upvotes: 1

Related Questions