<jupyter_start><jupyter_text>**1. Write a NumPy program to compute the multiplication of two given matrixes.**<jupyter_code>b = np.array([9,4,8,7,6,5,1,3,2,22,1,2])
c = np.array([22,4,8,7,9,5,1,4,2,22,1,2])

print(np.multiply(b,c))<jupyter_output>[198  16  64  49  54  25   1  12   4 484   1   4]<jupyter_text>**2. Write a NumPy program to compute the outer product of two given vectors.**<jupyter_code>b = np.array([9,4,8,7,6,5,1,3,2,22,1,2])
c = np.array([22,4,8,7,9,5,1,4,2,22,1,2])

print(np.outer(b,c))<jupyter_output>[[198  36  72  63  81  45   9  36  18 198   9  18]
 [ 88  16  32  28  36  20   4  16   8  88   4   8]
 [176  32  64  56  72  40   8  32  16 176   8  16]
 [154  28  56  49  63  35   7  28  14 154   7  14]
 [132  24  48  42  54  30   6  24  12 132   6  12]
 [110  20  40  35  45  25   5  20  10 110   5  10]
 [ 22   4   8   7   9   5   1   4   2  22   1   2]
 [ 66  12  24  21  27  15   3  12   6  66   3   6]
 [ 44   8  16  14  18  10   2   8   4  44   2   4]
 [484  88 176 154 198 110  22  88  44 484  22  44]
 [ 22   4   8   7   9   5   1   4   2  22   1   2]
 [ 44   8  16  14  18  10   2   8   4  44   2   4]]<jupyter_text>**3. Write a NumPy program to compute the cross product of two given vectors.**<jupyter_code>p = [[1, 0], [0, 1]]
q = [[1, 2], [3, 4]]

print(np.cross(p,q))
print(np.cross(q,p))<jupyter_output>[[1, 0], [0, 1]]
[ 2 -3]
[-2  3]<jupyter_text>**4. Write a NumPy program to compute the determinant of a given square array.**<jupyter_code>a = np.ones((3,3))
print(a)
print()
print(np.linalg.det(a))
import numpy as np
a = np.array([[1, 0], [1, 2]])
print("Original 2-d array")
print(a)
print("Determinant of the said 2-D array:")
print(np.linalg.det(a))<jupyter_output>Original 2-d array
[[1 0]
 [1 2]]
Determinant of the said 2-D array:
2.0<jupyter_text>**5. Write a NumPy program to evaluate Einstein's summation convention of two given multidimensional arrays.**<jupyter_code>import numpy as np
a = np.array([1,2,3])
b = np.array([0,1,0])
print("Original 1-d arrays:")
print(a)
print(b)
result =  np.einsum("n,n", a, b)
print("Einstein’s summation convention of the said arrays:")
print(result)
x = np.arange(9).reshape(3, 3)
y = np.arange(3, 12).reshape(3, 3)
print("Original Higher dimension:")
print(x)
print(y)
result = np.einsum("mk,kn", x, y)
print("Einstein’s summation convention of the said arrays:")
print(result)<jupyter_output>Original Higher dimension:
[[0 1 2]
 [3 4 5]
 [6 7 8]]
[[ 3  4  5]
 [ 6  7  8]
 [ 9 10 11]]
Einstein’s summation convention of the said arrays:
[[ 24  27  30]
 [ 78  90 102]
 [132 153 174]]<jupyter_text>**6. Write a NumPy program to compute the inner product of vectors for 1-D arrays (without complex conjugation) and in higher dimension.**<jupyter_code>p = np.array([3,4])
q = np.array([5,6])

print(np.inner(p,q))
import numpy as np
a = np.array([1,2,5])
b = np.array([2,1,0])
print("Original 1-d arrays:")
print(a)
print(b)
print 
result = np.inner(a, b)
print(result)
x = np.arange(9).reshape(3, 3)
y = np.arange(3, 12).reshape(3, 3)
print("Higher dimension arrays:")
print(x)
print(y)
print()
result = np.inner(x, y)
print("Inner product of the said vectors:")
print(result)<jupyter_output>Higher dimension arrays:
[[0 1 2]
 [3 4 5]
 [6 7 8]]
[[ 3  4  5]
 [ 6  7  8]
 [ 9 10 11]]

Inner product of the said vectors:
[[ 14  23  32]
 [ 50  86 122]
 [ 86 149 212]]<jupyter_text>**7. Write a NumPy program to compute the eigenvalues and right eigenvectors of a given square array.**<jupyter_code>import numpy as np
m = np.mat("3 -2;1 0")
print(m)
print()
x, y = np.linalg.eig(m)
print(x)
print()
print(y)<jupyter_output>[[ 3 -2]
 [ 1  0]]

[2. 1.]

[[0.89442719 0.70710678]
 [0.4472136  0.70710678]]<jupyter_text>**10. Write a NumPy program to find a matrix or vector norm.**<jupyter_code>#vector norm

import numpy as np
v = np.arange(7)
result = np.linalg.norm(v)
print("Vector norm:")
print(result)
#matrix norm

m = np.matrix('1, 2; 3, 4') 
result1 = np.linalg.norm(m)
print("Matrix norm:")
print(result1)<jupyter_output>Matrix norm:
5.477225575051661<jupyter_text>**11. Write a NumPy program to compute the determinant of an array.**<jupyter_code>v = np.arange(1,17).reshape(4,4)
print(v)
print()
print('Determinant of the array is:', np.linalg.det(v))
import numpy as np
a = np.array([[1,2],[3,4]])
print("Original array:")
print(a)
result =  np.linalg.det(a)
print("Determinant of the said array:")
print(result)<jupyter_output>Original array:
[[1 2]
 [3 4]]
Determinant of the said array:
-2.0000000000000004<jupyter_text>**12. Write a NumPy program to compute the inverse of a given matrix.**<jupyter_code>m = np.matrix('1, 2; 3, 4')
print(m)
print()

print(np.linalg.inv(m))
import numpy as np
m = np.array([[1,2],[3,4]])
print("Original matrix:")
print(m)
result =  np.linalg.inv(m)
print("Inverse of the said matrix:")
print(result)<jupyter_output>Original matrix:
[[1 2]
 [3 4]]
Inverse of the said matrix:
[[-2.   1. ]
 [ 1.5 -0.5]]<jupyter_text>**15. Write a NumPy program to compute the sum of the diagonal element of a given array.**<jupyter_code>import numpy as np
m = np.array([[1,2],[3,4]])
print(m)
print()
print(np.trace(m))
import numpy as np
m = np.arange(1,5).reshape(2,2)
print("Original matrix:")
print(m)
result =  np.trace(m)
print("Condition number of the said matrix:")
print(result)<jupyter_output>Original matrix:
[[1 2]
 [3 4]]
Condition number of the said matrix:
5<jupyter_text>**18. Write a NumPy program to compute the factor of a given array by Singular Value Decomposition.**<jupyter_code>import numpy as np
a = np.array([[1, 0, 0, 0, 2], [0, 0, 3, 0, 0], [0, 0, 0, 0, 0], [0, 2, 0, 0, 0]], dtype=np.float32)
print("Original array:")
print(a)
U, s, V = np.linalg.svd(a, full_matrices=False)
q, r = np.linalg.qr(a)
print("Factor of a given array  by Singular Value Decomposition:")
print("U=\n", U, "\ns=\n", s, "\nV=\n", V)<jupyter_output>Original array:
[[1. 0. 0. 0. 2.]
 [0. 0. 3. 0. 0.]
 [0. 0. 0. 0. 0.]
 [0. 2. 0. 0. 0.]]
Factor of a given array  by Singular Value Decomposition:
U=
 [[ 0.  1.  0.  0.]
 [ 1.  0.  0.  0.]
 [ 0.  0.  0. -1.]
 [ 0.  0.  1.  0.]] 
s=
 [3.       2.236068 2.       0.      ] 
V=
 [[-0.         0.         1.         0.         0.       ]
 [ 0.4472136  0.         0.         0.         0.8944272]
 [-0.         1.         0.         0.         0.       ]
 [ 0.         0.         0.         1.         0.       ]]
{'fraction_non_alphanumeric': 0.16614370881706936, 'fraction_numerical': 0.11421399435205522, 'mean_word_length': 3.1721204188481678, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 13, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '88639', 'license': 'MIT', 'n_tokens_mistral': 3091, 'n_tokens_neox': 2679, 'n_words': 838, 'path': 'Numpy Linear Algebra Exercises.ipynb', 'repo_name': 'abhijitvc/Numpy-and-Pandas', 'size': '6374'}