Month: March 2021

Python Example – Write a NumPy program to compute the inner product of vectors for 1-D array

Hits: 6 (Python Example for Beginners)   Write a NumPy program to compute the inner product of vectors for 1-D arrays (without complex conjugation) and in higher dimension.   Sample Solution : Python Code : 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(“Inner …

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

Hits: 7 (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, …

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

Hits: 6 (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 …

Python Example – Write a NumPy program to compute the multiplication of two given matrixes

Hits: 5 (Python Example for Beginners)   Write a NumPy program to compute the multiplication of two given matrixes. Sample Matrix: [[1, 0], [0, 1]] [[1, 2], [3, 4]]   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) …

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

Hits: 3 (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 …

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

Hits: 8 (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 …

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

Hits: 1 (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 – Write a Python program to check if a given positive integer is a power of two

Hits: 4 (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 …

Java tutorials for Beginners – Java ObjectInputStream Class

Hits: 26 (Java programming Example for Beginners) Java ObjectInputStream Class In this tutorial, we will learn about Java ObjectOutputStream and its methods with the help of examples. The ObjectInputStream class of the java.io package can be used to read objects that were previously written by ObjectOutputStream. It extends the InputStream abstract class. Before you learn about the ObjectInputStream class, make sure you know about …

Java tutorials for Beginners – Java ByteArrayInputStream Class

Hits: 10 (Java programming Example for Beginners) Java ByteArrayInputStream Class In this tutorial, we will learn about Java ByteArrayInputStream and its methods with the help of examples. The ByteArrayInputStream class of the java.io package can be used to read an array of input data (in bytes). It extends the InputStream abstract class. Note: In ByteArrayInputStream, the input stream is created using the …

Java tutorials for Beginners – Java FileInputStream Class

Hits: 6 (Java programming Example for Beginners) Java FileInputStream Class In this tutorial, we will learn about Java FileInputStream and its methods with the help of examples. The FileInputStream class of the java.io package can be used to read data (in bytes) from files. It extends the InputStream abstract class. Before we learn about FileInputStream, make sure to know about Java Files. Create …

Python Example – Write a Python program to create a Pythagorean theorem calculator

Hits: 17 (Python Example for Beginners)   Write a Python program to create a Pythagorean theorem calculator. Note : In mathematics, the Pythagorean theorem, also known as Pythagoras’ theorem, is a fundamental relation in Euclidean geometry among the three sides of a right triangle. It states that the square of the hypotenuse (the side opposite …

Python Example – Write a Python program to create a simple math quiz

Hits: 20 (Python Example for Beginners)   Write a Python program to create a simple math quiz.   Sample Solution: Python Code: import random def display_intro(): title = “** A Simple Math Quiz **” print(“*” * len(title)) print(title) print(“*” * len(title)) def display_menu(): menu_list = [“1. Addition”, “2. Subtraction”, “3. Multiplication”, “4. Integer Division”, “5. …

Python Example – Write a Python program to parse math formulas and put parentheses around multiplication and division

Hits: 11 (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, …

Java tutorials for Beginners – Java ListIterator

Hits: 6 (Java programming Example for Beginners) Java ListIterator Interface In this tutorial, we will learn about the Java ListIterator interface with the help of an example. The ListIterator interface of the Java collections framework provides the functionality to access elements of a list. It is bidirectional. This means it allows us to iterate elements of a …