corewise_stack_norm#

t3toolbox.corewise.corewise_stack_norm(X, n_stack)#
def corewise_stack_norm(
        X:          NDArrayTree,  # tree; each leaf shape = stack_shape + (core dims)
        n_stack:    int,          # number of leading stack axes kept (one norm per stack slice)
) -> NDArray:  # array of shape = common stack_shape (scalar when n_stack==0)

Like corewise_norm(), but vectorized over the leading n_stack (stack) axes.

Returns an array of shape equal to the common leading stack shape – one norm per stack slice (a scalar when n_stack == 0, matching corewise_norm()). It is the sqrt of the per-slice corewise_stack_dot() of X with itself. Use this (not corewise_norm(), which collapses every axis including the stack) for a vectorized norm.

Examples

>>> import numpy as np
>>> import t3toolbox.corewise as cw
>>> X = (np.ones((2, 3)), np.ones((2, 4, 5)))   # stack=(2,), then core axes
>>> print(cw.corewise_stack_norm(X, 1))         # sqrt(3 + 20) per slice
[4.79583152 4.79583152]
Parameters:
Return type:

NDArray