<jupyter_start><jupyter_text>Practice Answers  Practice Number 1 1. Given the linear combination below, try to create a corresponding matrix representing it. $$\theta = 5x + 3y - z$$<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import scipy.linalg as la
%matplotlib inline

def describe_mat (matrix):
    is_square = True if matrix.shape[0] == matrix.shape[1] else False
    print(f'Matrix:\n{matrix}\n\nShape:\t{matrix.shape}\nRank:\t{matrix.ndim}\n')
theta = np.array ([
  [5,3,-1]
])
describe_mat(theta)<jupyter_output>Matrix:
[[ 5  3 -1]]

Shape:	(1, 3)
Rank:	2<jupyter_text>Practice Number 2 2. Given the system of linear combinations below, try to encode it as a matrix. Also describe the matrix. $$A = \left\{\begin{array}5x_1 + 2x_2 +x_3\\4x_2 - x_3\\10x_3\end{array}\right.$$<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import scipy.linalg as la
%matplotlib inline
def describe_mat(matrix):
    is_square = True if matrix.shape[0] == matrix.shape[1] else False
    print(f'Matrix:\n{matrix}\n\nShape:\t{matrix.shape}\nRank:\t{matrix.ndim}\nIs square: {is_square}\n')
D = np.array ([
   [1,2,1],
   [0,4,-1],
   [0,0,10]                     
])
describe_mat(D)<jupyter_output>Matrix:
[[ 1  2  1]
 [ 0  4 -1]
 [ 0  0 10]]

Shape:	(3, 3)
Rank:	2
Is square: True<jupyter_text>Practice Number 3 3. Given the matrix below, express it as a linear combination in a markdown.<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import scipy.linalg as la
%matplotlib inline
G = np.array([
    [1,7,8],
    [2,2,2],
    [4,6,7]
])<jupyter_output><empty_output><jupyter_text>$$G = \left\{    \begin{array}\        x + 7y + 8z \\        2x + 2y + 2z \\        4x + 6y + 7z \\    \end{array}\right. \\ $$  Practice Number 4 4. Given the matrix below, display the output as a LaTeX makdown also express it as a system of linear combinations.<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import scipy.linalg as la
%matplotlib inline
H = np.tril(G)
H<jupyter_output><empty_output><jupyter_text>$$G = \left\{    \begin{array}\        x  \\        2x + 2y \\        4x + 6y +7z \\    \end{array}\right. \\ $$ $$ G=\begin{bmatrix} 1 & 0 & 0 \\ 2 & 2 & 0 \\ 4 & 6 & 7\end{bmatrix}$$  Tasks **Task 1** Create a function named mat_desc() that thouroughly describes a matrix , it should:  1. Displays the shape, size and rank of the matrix.  2. Displays whether the matrix is a square or non-square.  3. Displays whether the matrix is an empty matrix.  4. Displays if the matrix is an identity, ones or zeros matrix.Use samples 3 matrices in which their shapes are not lower than **(3,3)**. In your methodology, create a flowchart discuss the functions and methods you have done. Present your results in the results section showing the description of each matrix you have declared.<jupyter_code>def describe_mat (matrix):
      print(f'Matrix:\n{matrix}\n\nShape:\t{matrix.shape}\nRank"\t{matrix.ndim}\n')<jupyter_output><empty_output><jupyter_text>**Shape, Size and Rank**<jupyter_code>Z = np.array([
    [8, 6, 2, 4],
    [4, 7, 9, 1],
    [10, 9, 8, 7],
    [23, 6, 11, 5]
])
describe_mat(Z)
Y = np.array([
    [2, 4, 6, 8, 10],
    [3, 6, 9, 12, 15],
    [4, 8, 12, 16, 20],
    [5, 10, 15, 20, 25]
])
describe_mat(Y)
X = np.array([
    [1, 2, 3, 4,],
    [10, 9, 8, 7],
    [4, 6, 8, 10],
    [14, 7, 9, 1],
    [4, 8, 5, 67]
])
describe_mat(X)<jupyter_output>Matrix:
[[ 1  2  3  4]
 [10  9  8  7]
 [ 4  6  8 10]
 [14  7  9  1]
 [ 4  8  5 67]]

Shape:	(5, 4)
Rank"	2<jupyter_text>**Square and Non-Square Matrices**<jupyter_code>def mat_desc(matrix):
  is_square = True if matrix.shape[0] == matrix.shape[1] else False
  print(f'Matrix:\n{matrix}\n\nShape:\t{matrix.shape}\nRank:\t{matrix.ndim}\n')
square_mat = np.array([
    [3, 8, 7, 9],
    [9, 8, 3, 5],
    [6, 2, 7, 5],
    [1, 6, 0, 4]
])

non_square_mat = np.array([
    [5, 7, 3, 6, 0],
    [3, 78, 14, 17, 5],
    [56, 1, 3, 90, 4],
    [5, 24, 10, 11, 9]
])

mat_desc(square_mat)
mat_desc(non_square_mat)
square_mat = np.array([
    [4, 8, 12, 91],
    [23, 16, 7, 10],
    [56, 12, 45, 1],
    [9, 41, 34, 7]
])

non_square_mat = np.array([
    [23, 78, 14, 56, 89],
    [67, 10 , 11, 56, 34],
    [43, 92, 12, 0, 4],
    [78, 101, 79, 34, 2]
])

mat_desc(square_mat)
mat_desc(non_square_mat)
square_mat = np.array([
    [3, 4, 5, 6],
    [1, 2, 3, 4],
    [9, 8, 7, 6],
    [4, 6, 2, 6]
])

non_square_mat = np.array([
    [4, 7, 2, 8, 9],
    [12, 87, 46, 23, 1],
    [23, 67, 12, 40, 1],
    [56, 17, 19, 23, 65]
])

mat_desc(square_mat)
mat_desc(non_square_mat)<jupyter_output>Matrix:
[[3 4 5 6]
 [1 2 3 4]
 [9 8 7 6]
 [4 6 2 6]]

Shape:	(4, 4)
Rank:	2

Matrix:
[[ 4  7  2  8  9]
 [12 87 46 23  1]
 [23 67 12 40  1]
 [56 17 19 23 65]]

Shape:	(4, 5)
Rank:	2<jupyter_text>**Empty Matrix**<jupyter_code>def mat_desc(matrix):
  if matrix.size > 0:
    is_square = True if matrix.shape[0] == matrix.shape[1] else False
    print(f'Matrix:\n{matrix}\n\nShape:\t{matrix.shape}\nRank:\t{matrix.ndim}\n')
  else:
    print('Matrix is Null')
null_mat = np.array([])
mat_desc(null_mat)<jupyter_output>Matrix is Null<jupyter_text>**Identity**<jupyter_code>np. eye (5)
np.identity (10)
np.eye (16)<jupyter_output><empty_output><jupyter_text>**Ones**<jupyter_code>ones_mat_row = np.ones((9,5))
ones_mat_sqr = np.ones((6,5))
ones_mat_rct = np.ones((7,4))

print(f'ones Row Matrix: \n{ones_mat_row}')
print(f'ones Square Matrix: \n{ones_mat_sqr}')
print(f'ones Rectangular Matrix: \n{ones_mat_rct}')<jupyter_output>ones Row Matrix: 
[[1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1.]]
ones Square Matrix: 
[[1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1.]]
ones Rectangular Matrix: 
[[1. 1. 1. 1.]
 [1. 1. 1. 1.]
 [1. 1. 1. 1.]
 [1. 1. 1. 1.]
 [1. 1. 1. 1.]
 [1. 1. 1. 1.]
 [1. 1. 1. 1.]]<jupyter_text>**Zeros**<jupyter_code>zero_mat_row = np.zeros((8,3))
zero_mat_sqr = np.zeros((4,4))
zero_mat_rct = np.zeros((7,5))

print(f'Zero Row Matrix: \n{zero_mat_row}')
print(f'Zero Square Matrix: \n{zero_mat_sqr}')
print(f'Zero Rectangular Matrix: \n{zero_mat_rct}')<jupyter_output>Zero Row Matrix: 
[[0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]]
Zero Square Matrix: 
[[0. 0. 0. 0.]
 [0. 0. 0. 0.]
 [0. 0. 0. 0.]
 [0. 0. 0. 0.]]
Zero Rectangular Matrix: 
[[0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0.]]<jupyter_text>**Task 2**<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import scipy.linalg as la
%matplotlib inline
def mat_operations(mat1, mat2):
    mat1 = np.array(mat1)
    mat2 = np.array(mat2)
    print('Matrix 1:', mat1)
    print('Matrix 2:', mat2)
    if(mat1.shape != mat2.shape):
        print('The shape of both matrices are not same. Could not perform operations.')
        return
    print('Sum of the given matrices:')
    msum = mat1 + mat2
    print(msum)
    print('Difference of the given matrices:')
    mdiff = mat1 - mat2
    print(mdiff)
    print('Element-wise multiplication of the given matrices:')
    mmul = np.multiply(mat1, mat2)
    print(mmul)
    print('Element-wise division of the given matrices:')
    mmul = np.divide(mat1, mat2)
    print(mmul)
mat_operations([
    [5,2,7,4,4,3], 
    [8,9,9,5,8,6],
    [1,2,3,4,5,6],
    [2,4,6,8,10,0]],

    [[9,8,7,6,5,4], 
    [4,2,1,1,0,3],
    [7,2,5,8,3,6],
    [4,1,0,2,5,8]])

def mat_operations(mat1, mat2):
    mat1 = np.array(mat1)
    mat2 = np.array(mat2)
    print('Matrix 1:', mat1)
    print('Matrix 2:', mat2)
    if(mat1.shape != mat2.shape):
        print('The shape of both matrices are not same. Could not perform operations.')
        return
    print('Sum of the given matrices:')
    msum = mat1 + mat2
    print(msum)
    print('Difference of the given matrices:')
    mdiff = mat1 - mat2
    print(mdiff)
    print('Element-wise multiplication of the given matrices:')
    mmul = np.multiply(mat1, mat2)
    print(mmul)
    print('Element-wise division of the given matrices:')
    mmul = np.divide(mat1, mat2)
    print(mmul)
mat_operations([
    [3,1,2,3,4,5], 
    [6,5,7,7,6,9],
    [2,4,9,3,5,4],
    [3,4,6,4,8,9]],

    [[1,4,3,3,9,3], 
    [1,6,2,5,1,4],
    [2,9,1,8,1,5],
    [3,6,8,6,8,6]])<jupyter_output>Matrix 1: [[3 1 2 3 4 5]
 [6 5 7 7 6 9]
 [2 4 9 3 5 4]
 [3 4 6 4 8 9]]
Matrix 2: [[1 4 3 3 9 3]
 [1 6 2 5 1 4]
 [2 9 1 8 1 5]
 [3 6 8 6 8 6]]
Sum of the given matrices:
[[ 4  5  5  6 13  8]
 [ 7 11  9 12  7 13]
 [ 4 13 10 11  6  9]
 [ 6 10 14 10 16 15]]
Difference of the given matrices:
[[ 2 -3 -1  0 -5  2]
 [ 5 -1  5  2  5  5]
 [ 0 -5  8 -5  4 -1]
 [ 0 -2 -2 -2  0  3]]
Element-wise multiplication of the given matrices:
[[ 3  4  6  9 36 15]
 [ 6 30 14 35  6 36]
 [ 4 36  9 24  5 20]
 [ 9 24 48 24 64 54]]
Element-wise division of the given matrices:
[[3.         0.25       0.66666667 1.         0.44444444 1.66666667]
 [6.         0.83333333 3.5        1.4        6.         2.25      ]
 [1.         0.44444444 9.         0.375      5.         0.8       ]
 [1.         0.66666667 0.75       0.66666667 1.         1.5       ]]
{'fraction_non_alphanumeric': 0.18117114202523454, 'fraction_numerical': 0.1064380459398253, 'mean_word_length': 2.68015873015873, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 7, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '62258', 'license': 'Apache-2.0', 'n_tokens_mistral': 4647, 'n_tokens_neox': 4036, 'n_words': 1206, 'path': 'LabRep2.ipynb', 'repo_name': 'StephanyLera/Linear-Algebra_2nd-Sem', 'size': '9273'}