<jupyter_start><jupyter_text>matrix multiplication<jupyter_code>print(arr1.dot(arr2))
# or
print(np.dot(arr1, arr2))
# or
print(arr1 @ arr2)<jupyter_output>[[1.31252776 0.97959602 1.04562177 1.46872849 0.82346985]
 [0.57189002 0.52485513 0.6974257  0.70011061 0.68537337]
 [0.7021696  0.85146355 1.20523878 0.90775039 1.2998992 ]
 [1.00630752 0.99472846 1.16669167 1.06176843 1.0317387 ]
 [1.50082083 1.33223036 1.47193944 1.70380111 1.34317336]]
[[1.31252776 0.97959602 1.04562177 1.46872849 0.82346985]
 [0.57189002 0.52485513 0.6974257  0.70011061 0.68537337]
 [0.7021696  0.85146355 1.20523878 0.90775039 1.2998992 ]
 [1.00630752 0.99472846 1.16669167 1.06176843 1.0317387 ]
 [1.50082083 1.33223036 1.47193944 1.70380111 1.34317336]]
[[1.31252776 0.97959602 1.04562177 1.46872849 0.82346985]
 [0.57189002 0.52485513 0.6974257  0.70011061 0.68537337]
 [0.7021696  0.85146355 1.20523878 0.90775039 1.2998992 ]
 [1.00630752 0.99472846 1.16669167 1.06176843 1.0317387 ]
 [1.50082083 1.33223036 1.47193944 1.70380111 1.34317336]]<jupyter_text>QR factorization<jupyter_code>arr = np.random.rand(5,5)

q, r = np.linalg.qr(arr)
print(q)
print(r)<jupyter_output>[[-0.70587399 -0.10465788  0.60113926 -0.0267876  -0.35875153]
 [-0.54610348 -0.49295842 -0.4513967  -0.17201361  0.47477924]
 [-0.25379769  0.34738697  0.03453889  0.81080678  0.39535864]
 [-0.14503423 -0.10064629 -0.58908925  0.36392496 -0.69954834]
 [-0.34360545  0.78436684 -0.29436972 -0.42408104 -0.01434168]]
[[-0.84698441 -1.25767968 -1.12329663 -0.94203706 -0.78685899]
 [ 0.          0.60393505  0.37048914 -0.41712377 -0.10680234]
 [ 0.          0.         -0.6688117  -0.57302335 -0.22413241]
 [ 0.          0.          0.          0.09166178  0.21059678]
 [ 0.          0.          0.          0.         -0.1688188 ]]<jupyter_text>singular value decomposition (SVD)<jupyter_code>arr = np.random.rand(5,5)

u, s, v = np.linalg.svd(arr)
print(u)
print(s)
print(v)<jupyter_output>[[-0.51582413  0.05340736 -0.69571428 -0.42334918  0.26044237]
 [-0.34775725 -0.842141    0.21629222  0.15550346  0.31448335]
 [-0.58401574  0.12177925  0.51003396 -0.4015491  -0.47193125]
 [-0.19493532  0.47928268  0.41313699  0.07759931  0.74537541]
 [-0.48364882  0.20833652 -0.19591453  0.79330374 -0.23444912]]
[2.96018519 0.93273137 0.62401273 0.40194888 0.26704925]
[[-0.48078664 -0.39309221 -0.42944155 -0.29921415 -0.58341544]
 [ 0.48711506 -0.50981326  0.52113532  0.06743482 -0.4761091 ]
 [-0.01840113  0.30579164 -0.20481209  0.81028409 -0.45568033]
 [ 0.00896271 -0.69463434 -0.31862447  0.44454422  0.46718486]
 [-0.7287964  -0.09769114  0.63287312  0.22747212  0.08390644]]<jupyter_text>compute eigen values<jupyter_code>arr = np.random.rand(5,5)
print(np.linalg.eigvals(arr))<jupyter_output>[ 2.57442096+0.j         -0.46004396+0.56206791j -0.46004396-0.56206791j
 -0.25673011+0.j          0.01785716+0.j        ]<jupyter_text>eigen value decomposition<jupyter_code>arr = np.random.rand(5,5)

w, v = np.linalg.eig(arr)
print(w)    # eigen values
print(v)    # eigen vectors<jupyter_output>[ 2.73661103+0.j         -0.01715451+0.56141968j -0.01715451-0.56141968j
 -0.25543635+0.j          0.22382747+0.j        ]
[[-0.40507237+0.j         -0.52280453+0.06471084j -0.52280453-0.06471084j
  -0.50291692+0.j         -0.64402754+0.j        ]
 [-0.52894602+0.j         -0.08687172-0.31451027j -0.08687172+0.31451027j
   0.61420091+0.j         -0.36336532+0.j        ]
 [-0.38604381+0.j          0.59168845+0.j          0.59168845-0.j
  -0.25138299+0.j          0.31358756+0.j        ]
 [-0.3882069 +0.j          0.04733147-0.21866252j  0.04733147+0.21866252j
  -0.19993459+0.j          0.48920281+0.j        ]
 [-0.50635764+0.j          0.16235405+0.43533538j  0.16235405-0.43533538j
   0.51639574+0.j          0.33990826+0.j        ]]<jupyter_text>compute the trace & determinant<jupyter_code># notice this is not a function in linalg!!!
print(np.trace(arr))    
print(np.linalg.det(arr))<jupyter_output>-0.04936165379461782<jupyter_text>calculate the inverse/psedo-inverse of a matrix<jupyter_code>arr = np.random.rand(5,5)
# compute the inverse of a matrix
print(np.linalg.inv(arr))
# compute the psudo-inverse of a matrix
print(np.linalg.pinv(arr))<jupyter_output>[[-0.9729108   0.68359843  0.27560095  0.31558263  0.06454983]
 [ 0.07756599  0.37670971 -0.95034846  0.07536458  1.19394609]
 [ 0.44376295 -0.35349158  1.60914268 -1.41864262  0.00861574]
 [ 0.82939409 -2.27873377  2.38781928  0.06971199 -0.39439425]
 [-0.07431272  4.34596577 -6.65563472  2.39012962  0.08796141]]<jupyter_text>solve a linear system<jupyter_code># solve a linear system in closed form
y = [1,2,3,4,5]
print(np.linalg.solve(arr, y))
# calculate the least-squares solution of a linear system
y = [1,2,3,4,5]
solution, residuals, rank, singular = np.linalg.lstsq(arr, y)
print(solution)
print(residuals)
print(rank)
print(singular)<jupyter_output>[ 2.80616855  4.25112878 -1.06728394  1.74226111 -1.34895981]
[]
5
[2.45425469 0.89773066 0.73143991 0.57608405 0.10952437]
{'fraction_non_alphanumeric': 0.1474755537816803, 'fraction_numerical': 0.46358012372779883, 'mean_word_length': 3.1490066225165565, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '573452', 'license': 'MIT', 'n_tokens_mistral': 3699, 'n_tokens_neox': 2441, 'n_words': 360, 'path': '10. Linear Algebra.ipynb', 'repo_name': 'therealhaseeb/Numpy-Tutorial', 'size': '5011'}