(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 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 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 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 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 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 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 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 …
(Python Example for Beginners) Write a Python program to parse math formulas and put parentheses around multiplication and division. Sample Solution: Python Code: import ast def recurse(node): if isinstance(node, ast.BinOp): if isinstance(node.op, ast.Mult) or isinstance(node.op, ast.Div): print(‘(‘, end=”) recurse(node.left) recurse(node.op) recurse(node.right) if isinstance(node.op, ast.Mult) or isinstance(node.op, ast.Div): print(‘)’, end=”) elif isinstance(node, ast.Add): print(‘+’, …
(Python Example for Beginners) Write a Python program to calculate the standard deviation of the following data. Sample Solution: Python Code: import math import sys def sd_calc(data): n = len(data) if n <= 1: return 0.0 mean, sd = avg_calc(data), 0.0 # calculate stan. dev. for el in data: sd += (float(el) – …