summaryrefslogtreecommitdiff
path: root/lj_matrix/frob_norm.py
diff options
context:
space:
mode:
authorDavid Luevano <55825613+luevano@users.noreply.github.com>2020-01-23 18:59:34 -0700
committerDavid Luevano <55825613+luevano@users.noreply.github.com>2020-01-23 18:59:34 -0700
commit6e9b439d4b3d303b246d9e66b3ed3852e3fad9a5 (patch)
treee9c04b1af5552fc149f26553e7e53735f57cf435 /lj_matrix/frob_norm.py
parent5a48f2e69e301875c7d86f40ae1dab5d27f7fd0f (diff)
Rename lj_matrix to ml_exp
Diffstat (limited to 'lj_matrix/frob_norm.py')
-rw-r--r--lj_matrix/frob_norm.py51
1 files changed, 0 insertions, 51 deletions
diff --git a/lj_matrix/frob_norm.py b/lj_matrix/frob_norm.py
deleted file mode 100644
index 4c3a2945d..000000000
--- a/lj_matrix/frob_norm.py
+++ /dev/null
@@ -1,51 +0,0 @@
-"""MIT License
-
-Copyright (c) 2019 David Luevano Alvarado
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-"""
-import math
-
-
-def frob_norm(array):
- """
- Calculates the frobenius norm of a given array or matrix.
- array: array of data.
- """
-
- arr_sh_len = len(array.shape)
- arr_range = range(len(array))
- fn = 0.0
-
- # If it is a 'vector'.
- if arr_sh_len == 1:
- for i in arr_range:
- fn += array[i]*array[i]
-
- return math.sqrt(fn)
-
- # If it is a matrix.
- elif arr_sh_len == 2:
- for i in arr_range:
- for j in arr_range:
- fn += array[i, j]*array[i, j]
-
- return math.sqrt(fn)
- else:
- print('Error. Array size greater than 2 ({}).'.format(arr_sh_len))