inducer / arraycontext

Choose your favorite numpy-workalike!
6 stars 11 forks source link

Mimic numpy's norm when ord is None #30

Closed kaushikcfd closed 3 years ago

kaushikcfd commented 3 years ago

I couldn't find a mention for this in the numpy docs, but here is a small script:

In [2]: a = np.random.rand(3, 3, 3, 3, 3)

In [3]: np.linalg.norm(a)
Out[3]: 8.718438810223871

In [4]: np.linalg.norm(a.ravel(), ord=2)
Out[4]: 8.718438810223871

Let me know what do you guys think.

inducer commented 3 years ago

Thanks! If you add a test showing that the behavior matches numpy, I could see going along with this. @alexfikl?

kaushikcfd commented 3 years ago

If you add a test showing that the behavior matches numpy

Done! See 1bae084.

alexfikl commented 3 years ago

Thanks! If you add a test showing that the behavior matches numpy, I could see going along with this. @alexfikl?

Yeah, this should match the docs for linalg.norm:

If both axis and ord are None, the 2-norm of x.ravel will be returned.
inducer commented 3 years ago

LGTM. Thanks!