<jupyter_start><jupyter_text>TASK 1<jupyter_code>import numpy as np
 
def mat_desc(matrix):           
    MShape = matrix.shape
    MSize = matrix.size
    MRank = matrix.ndim
    
    IsSquare = MShape[0] == MShape[1] 
 
    print(f'Matrix:\n{matrix}\n\nShape:\t{MShape}\nSize:\t{MSize}\nRank:\t{MRank}\n')
    print(f'Is Empty: {MSize == 0}\nIs Square: {IsSquare}\n') 
 
    IsIdentity = np.sum(np.identity(MShape[0]) == matrix) == MSize
    total = np.sum(matrix)
 
    IsOne = False
    IsZero = False
 
    if total == MSize:
        IsOne = True
    elif total == 0:
        IsZero = True         
 
    print(f'Is Identity: {IsIdentity}\nIs One Matrix: {IsOne}\nIs Zero Matrix: {IsZero}\n')  
 
A = np.array([[0, 3, 2, 4], [2, 0, 1, 4], [1, 3, 0, 3], [2, 4, 5, 1]])
B = np.array([[2, 9, 6],[0, 3, 5],[0, 0, 9], [2, 4, 6]])
C = np.array([[1, 0, 0, 0, 0],[0, 1, 0, 0, 0],[0, 0, 1, 0, 0],[0, 0, 0, 1, 0],[0, 0, 0, 0, 1]])
D = np.array([[0, 0, 0],[0, 0, 0],[0, 0, 0]])
E = np.array([[1, 1, 1, 1],[1, 1, 1, 1],[1, 1, 1, 1],[1, 1, 1, 1]])
 
matrices = [A, B, C, D, E]
 
for i in matrices:
    mat_desc(i)
    print('end of result'.center(40,'-'))<jupyter_output>Matrix:
[[0 3 2 4]
 [2 0 1 4]
 [1 3 0 3]
 [2 4 5 1]]

Shape:	(4, 4)
Size:	16
Rank:	2

Is Empty: False
Is Square: True

Is Identity: False
Is One Matrix: False
Is Zero Matrix: False

-------------end of result--------------
Matrix:
[[2 9 6]
 [0 3 5]
 [0 0 9]
 [2 4 6]]

Shape:	(4, 3)
Size:	12
Rank:	2

Is Empty: False
Is Square: False

Is Identity: False
Is One Matrix: False
Is Zero Matrix: False

-------------end of result--------------
Matrix:
[[1 0 0 0 0]
 [0 1 0 0 0]
 [0 0 1 0 0]
 [0 0 0 1 0]
 [0 0 0 0 1]]

Shape:	(5, 5)
Size:	25
Rank:	2

Is Empty: False
Is Square: True

Is Identity: True
Is One Matrix: False
Is Zero Matrix: False

-------------end of result--------------
Matrix:
[[0 0 0]
 [0 0 0]
 [0 0 0]]

Shape:	(3, 3)
Size:	9
Rank:	2

Is Empty: False
Is Square: True

Is Identity: False
Is One Matrix: False
Is Zero Matrix: True

-------------end of result--------------
Matrix:
[[1 1 1 1]
 [1 1 1 1]
 [1 1 1 1]
 [1 1 1 1]]

Shape:	(4, 4)
Size:	16
Rank:	2

Is Empty: False
Is Square: T[...]<jupyter_text>TASK 2<jupyter_code>import numpy as np
 
class DimensionError(Exception):
    pass
 
def mat_desc(matrix):           
    MShape = matrix.shape
    MSize = matrix.size
    MRank = matrix.ndim
 
    IsSquare = MShape[0] == MShape[1]
 
    print(f'Matrix:\n{matrix}\n\nShape:\t{MShape}\nSize:\t{MSize}\nRank:\t{MRank}\n')
    print(f'Is Empty: {MSize == 0}\nIs Square: {IsSquare}\n')
 
    IsIdentity = np.sum(np.identity(MShape[0]) == matrix) == MSize
    total = np.sum(matrix)
 
    IsOne = False
    IsZero = False
 
    if total == MSize:
        IsOne = True
    elif total == 0:
        IsZero = True         
 
    print(f'Is Identity: {IsIdentity}\nIs One Matrix: {IsOne}\nIs Zero Matrix: {IsZero}\n')
 
def mat_operations(matrix1, matrix2):
    return_bool = False
    if not isinstance(matrix1, np.ndarray):
        print(f'{matrix1} is not a matrix.')
        return_bool = True
    if not isinstance(matrix2, np.ndarray):
        print(f'{matrix2} is not a matrix.') 
        return_bool = True
    if return_bool == True:
        return ''
 
    mat_desc(matrix1)
    print('end for Matrix 1'.center(40,'-'))
    mat_desc(matrix2)
    print('end for Matrix 2'.center(40,'-'))
 
    if matrix1.shape != matrix2.shape:
        raise DimensionError("The two matrices input have different dimensions")
 
    sum = matrix1 + matrix2
    diff = matrix1 - matrix2
    mult = matrix1 * matrix2
    divi = matrix1 / matrix2
 
    return [sum, diff, mult, divi]
 
A = np.array([[0, 3, 2, 4], [2, 0, 1, 4], [1, 3, 0, 3], [2, 4, 5, 1]])
B = np.array([[2, 9, 6],[0, 3, 5],[0, 0, 9], [2, 4, 6]])
C = np.array([[1, 0, 0, 0, 0],[0, 1, 0, 0, 0],[0, 0, 1, 0, 0],[0, 0, 0, 1, 0],[0, 0, 0, 0, 1]])
D = np.array([[0, 0, 0],[0, 0, 0],[0, 0, 0]])
E = np.array([[1, 1, 1, 1],[1, 1, 1, 1],[1, 1, 1, 1],[1, 1, 1, 1]])
 
print(mat_operations(A, E))<jupyter_output>Matrix:
[[0 3 2 4]
 [2 0 1 4]
 [1 3 0 3]
 [2 4 5 1]]

Shape:	(4, 4)
Size:	16
Rank:	2

Is Empty: False
Is Square: True

Is Identity: False
Is One Matrix: False
Is Zero Matrix: False

------------end for Matrix 1------------
Matrix:
[[1 1 1 1]
 [1 1 1 1]
 [1 1 1 1]
 [1 1 1 1]]

Shape:	(4, 4)
Size:	16
Rank:	2

Is Empty: False
Is Square: True

Is Identity: False
Is One Matrix: True
Is Zero Matrix: False

------------end for Matrix 2------------
[array([[1, 4, 3, 5],
       [3, 1, 2, 5],
       [2, 4, 1, 4],
       [3, 5, 6, 2]]), array([[-1,  2,  1,  3],
       [ 1, -1,  0,  3],
       [ 0,  2, -1,  2],
       [ 1,  3,  4,  0]]), array([[0, 3, 2, 4],
       [2, 0, 1, 4],
       [1, 3, 0, 3],
       [2, 4, 5, 1]]), array([[0., 3., 2., 4.],
       [2., 0., 1., 4.],
       [1., 3., 0., 3.],
       [2., 4., 5., 1.]])]
{'fraction_non_alphanumeric': 0.21697918813105296, 'fraction_numerical': 0.08324747578817226, 'mean_word_length': 2.27088948787062, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '229651', 'license': 'Apache-2.0', 'n_tokens_mistral': 2345, 'n_tokens_neox': 2020, 'n_words': 691, 'path': 'Week 7/LinAlg_58051_Gonzales_Matrices.ipynb', 'repo_name': 'diecilyngonzales/Lab-Activities-for-Linear-Algebra-58051', 'size': '4853'}