Day: March 31, 2021

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

(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 product of …

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 compute the multiplication of two given matrixes

(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) result1 = …

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 …

Java tutorials for Beginners – Java ObjectInputStream Class

(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 the ObjectOutputStream Class. …