Python for Citizen Data Scientist

Python Example – Write a NumPy program to generate six random integers between 10 and 30

(Python Example for Beginners)   Write a NumPy program to generate six random integers between 10 and 30.   Sample Solution: Python Code: import numpy as np x = np.random.randint(low=10, high=30, size=6) print(x) Sample Output: [14 25 20 12 27 22] Pictorial Presentation:   Python Example – Write a NumPy program to generate six random …

Python Example – Write a NumPy program to generate six random integers between 10 and 30

(Python Example for Beginners)   Write a NumPy program to generate six random integers between 10 and 30.   Sample Solution: Python Code: import numpy as np x = np.random.randint(low=10, high=30, size=6) print(x) Sample Output: [14 25 20 12 27 22]     Python Example – Write a NumPy program to generate six random integers …

Python Example – Write a NumPy program to generate six random integers between 10 and 30

(Python Example for Beginners)   Write a NumPy program to generate six random integers between 10 and 30.   Sample Solution: Python Code: import numpy as np x = np.random.randint(low=10, high=30, size=6) print(x) Sample Output: [14 25 20 12 27 22]     Python Example – Write a NumPy program to generate six random integers …

Python Example – Write a NumPy program to calculate the Frobenius norm and the condition number of a given array

(Python Example for Beginners)   Write a NumPy program to calculate the Frobenius norm and the condition number of a given array.   Sample Solution: Python Code : import numpy as np a = np.arange(1, 10).reshape((3, 3)) print(“Original array:”) print(a) print(“Frobenius norm and the condition number:”) print(np.linalg.norm(a, ‘fro’)) print(np.linalg.cond(a, ‘fro’)) Sample Output: Original array: [[1 …

Python Example – Write a NumPy program to get the qr factorization of a given array

(Python Example for Beginners)   Write a NumPy program to get the qr factorization of a given array.   Sample Solution: Python Code : import numpy as np a = np.array([[4, 12, -14], [12, 37, -53], [-14, -53, 98]], dtype=np.int32) print(“Original array:”) print(a) q, r = np.linalg.qr(a) print(“qr factorization of the said array:”) print( “q=n”, …

Python Example – Write a NumPy program to compute the sum of the diagonal element of a given array

(Python Example for Beginners)   Write a NumPy program to compute the sum of the diagonal element of a given array.   Sample Solution: Python Code : import numpy as np m = np.arange(6).reshape(2,3) print(“Original matrix:”) print(m) result = np.trace(m) print(“Condition number of the said matrix:”) print(result) Sample Output: Original matrix: [[0 1 2] [3 …

Python Example – Write a NumPy program to compute the condition number of a given matrix

(Python Example for Beginners)   Write a NumPy program to compute the condition number of a given matrix. From Wikipedia: In the field of numerical analysis, the condition number of a function with respect to an argument measures how much the output value of the function can change for a small change in the input …

Python Example – Write a NumPy program to calculate the QR decomposition of a given matrix

(Python Example for Beginners)   Write a NumPy program to calculate the QR decomposition of a given matrix. From Wikipedia: In linear algebra, a QR decomposition (also called a QR factorization) of a matrix is a decomposition of a matrix A into a product A = QR of an orthogonal matrix Q and an upper …

Python Example – Write a NumPy program to compute the inverse of a given matrix

(Python Example for Beginners)   Write a NumPy program to compute the inverse of a given matrix.   Sample Solution : Python Code : 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) Sample Output: Original matrix: [[1 2] [3 4]] Inverse of the said matrix: …

Python Example – Write a NumPy program to compute the determinant of an array

(Python Example for Beginners)   Write a NumPy program to compute the determinant of an array. From Wikipedia: In linear algebra, the determinant is a value that can be computed from the elements of a square matrix. The determinant of a matrix A is denoted det(A), det A, or |A|. Geometrically, it can be viewed …