-
-
Notifications
You must be signed in to change notification settings - Fork 11.3k
ENH: linalg: Add an axis
argument to linalg.norm
#3387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Also fixed a bug that occurred with integer arrays and negative ord. For example, norm([1, 3], -1) returned 1.0, but the correct value is 0.75.
The vector/matrix dual-nature of this function mean that it has a pretty weird and overloaded calling convention. This is too bad, but, given that it is what it is -- shouldn't this API also support the ability to compute matrix norms over some subset of the axes? |
I agree about the "weirdness"--initially I created a new function, I think of the |
Yes.
|
…, in which case matrix norms of the collection of 2-D matrices are computed.
The PR has been updated to allow |
>>> m = np.arange(8).reshape(2,2,2) | ||
>>> norm(m, axis=(1,2)) | ||
array([ 3.74165739, 11.22497216]) | ||
>>> norm(m[0]), norm(m[1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it's better style (esp. pedagogical style) to replace m[0]
with m[0, :, :]
or m[0, ...]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
…, and tweak the norm function's docstring.
The latest commit makes the changes suggest by @njsmith |
+1 from me pending travis results. |
ENH: linalg: Add an `axis` argument to linalg.norm
Fixes numpy#5727 The axis argument was introduced in numpy#3387
Example:
axis
can be a 2-tuple:This PR also fixes a bug that occurs when computing the norm of an integer array with a negative
ord
. Before this change,norm([1,3], ord=-1)
returned the incorrect value 1.0. Now,