HackerRank Python

Linear Algebra in Python – HackerRank Solution

The NumPy module also comes with a number of built-in routines for linear algebra calculations. These can be found in the sub-module linalg. linalg.det The linalg.det tool computes the determinant of an array. print numpy.linalg.det([[1 , 2], [2, 1]]) #Output : -3.0 linalg.eigThe linalg.eig computes the eigenvalues and right eigenvectors of a square array. vals, vecs = …

Linear Algebra in Python – HackerRank Solution Read More »

Inner and Outer in Python – HackerRank Solution

innerThe inner tool returns the inner product of two arrays.  import numpy A = numpy.array([0, 1]) B = numpy.array([3, 4]) print numpy.inner(A, B) #Output : 4 outer The outer tool returns the outer product of two arrays. import numpy A = numpy.array([0, 1]) B = numpy.array([3, 4]) print numpy.outer(A, B) #Output : [[0 0] # [3 4]] Task : You …

Inner and Outer in Python – HackerRank Solution Read More »

Mean, Var, and Std in Python – HackerRank Solution

meanThe mean tool computes the arithmetic mean along the specified axis. import numpy my_array = numpy.array([ [1, 2], [3, 4] ]) print numpy.mean(my_array, axis = 0) #Output : [ 2. 3.] print numpy.mean(my_array, axis = 1) #Output : [ 1.5 3.5] print numpy.mean(my_array, axis = None) #Output : 2.5 print numpy.mean(my_array) #Output : 2.5  By …

Mean, Var, and Std in Python – HackerRank Solution Read More »