Revision aaae58cc70f03ac357af64aa1300ab00eaf9bb6d authored by JeanKossaifi on 23 October 2016, 18:50:41 UTC, committed by JeanKossaifi on 23 October 2016, 18:50:41 UTC
1 parent 1e94ea4
_norm.py
import numpy as np
# Author: Jean Kossaifi
def norm(tensor, order):
"""Computes the l-order norm of tensor
Parameters
----------
tensor : ndarray
order : int
Returns
-------
float
l-order norm of tensor
"""
if order == 1:
return np.sum(np.abs(tensor))
elif order == 2:
return np.sqrt(np.sum(tensor**2))
else:
return np.sum(np.abs(tensor)**order)**(1/order)
Computing file changes ...