Python for Data Analyst

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 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 …

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 compute the Kronecker product of two given multi-dimension arrays

(Python Example for Beginners)   Write a NumPy program to compute the Kronecker product of two given multi-dimension arrays. Note: In mathematics, the Kronecker product, denoted by ⊗, is an operation on two matrices of arbitrary size resulting in a block matrix. It is a generalization of the outer product (which is denoted by the …

Python Example – Write a NumPy program to evaluate Einstein’s summation convention of two given multidimensional arrays

(Python Example for Beginners)   Write a NumPy program to evaluate Einstein’s summation convention of two given multidimensional arrays. Note: In mathematics, especially in applications of linear algebra to physics, the Einstein notation or Einstein summation convention is a notational convention that implies summation over a set of indexed terms in a formula, thus achieving …

Python Example – Write a NumPy program to compute the outer product of two given vectors

(Python Example for Beginners)   Write a NumPy program to compute the outer product of two given vectors.   Sample Solution : Python Code : import numpy as np p = [[1, 0], [0, 1]] q = [[1, 2], [3, 4]] print(“original matrix:”) print(p) print(q) result = np.outer(p, q) print(“Outer product of the said two vectors:”) …

Python Example – Write a NumPy program to convert a list of numeric value into a one-dimensional NumPy array

(Python Example for Beginners)   Write a NumPy program to convert a list of numeric value into a one-dimensional NumPy array. Sample Solution: Python Code: import numpy as np l = [12.23, 13.32, 100, 36.32] print(“Original List:”,l) a = np.array(l) print(“One-dimensional NumPy array: “,a) Sample Output: Original List: [12.23, 13.32, 100, 36.32] One-dimensional NumPy array: …

Python Example – Write a Python program to find a missing number from a list

(Python Example for Beginners)   Write a Python program to find a missing number from a list.   Sample Solution: Python Code: def missing_number(num_list): return sum(range(num_list[0],num_list[-1]+1)) – sum(num_list) print(missing_number([1,2,3,4,6,7,8])) print(missing_number([10,11,12,14,15,16,17])) Sample Output: 5 13   Python Example – Write a Python program to find a missing number from a list Free Machine Learning & Data …

Python Example – Write a Python program to check if an integer is the power of another integer

(Python Example for Beginners)   Write a Python program to check if an integer is the power of another integer.   Sample Solution: Python Code: def is_Power(x, y): while (x%y == 0): x = x / y return x == 1 print(is_Power(16, 2)) print(is_Power(12, 2)) print(is_Power(81, 3)) Sample Output: True False True   Python Example …

Python Example – Write a Python program to check if a given positive integer is a power of two

(Python Example for Beginners)   Write a Python program to check if a given positive integer is a power of two.   Sample Solution: Python Code: def is_Power_of_two(n): return n > 0 and (n & (n – 1)) == 0 print(is_Power_of_two(4)) print(is_Power_of_two(36)) print(is_Power_of_two(16)) Sample Output: True False True   Python Example – Write a Python …