You've successfully subscribed to The Poor Coder | Hackerrank Solutions
Great! Next, complete checkout for full access to The Poor Coder | Hackerrank Solutions
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.

Numpy

Beeze Aal

Hackerrank Mean, Var, and Std Solution

mean The 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
Beeze Aal

Hackerrank Polynomials Solution

poly The poly tool returns the coefficients of a polynomial with the given sequence of roots. print numpy.poly([-1, 1, 1, 10]) #Output : [ 1 -11 9 11 -10] roots The roots tool returns the roots of a polynomial with the given coefficients. print numpy.roots([1, 0, -1]) #Output
Beeze Aal

Hackerrank Linear Algebra 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.eig The linalg.
Beeze Aal

Hackerrank Eye and Identity Solution

Solution in python3Approach 1. import numpy print(numpy.eye(*map(int,input().split())))Approach 2. import numpy N, M = map(int, input().split()) print(numpy.eye(N, M))Solution in python import numpy N,M = map(int,raw_input().split()) print numpy.eye(N,M)
Beeze Aal

Hackerrank Zeros and Ones Solution

Solution in python3Approach 1. import numpy N = list(map(int, input().split())) print(numpy.zeros(N, int)) print(numpy.ones(N, int))Approach 2. import numpy size = tuple(map(int,input().strip().split())) print( numpy.zeros(size, int) ) print( numpy.ones(size, int) )Approach 3. import numpy N = [int(x)
Beeze Aal

Hackerrank Floor, Ceil and Rint Solution

Solution in python3Approach 1. import numpy a = numpy.array(input().split(),float) print(numpy.floor(a),numpy.ceil(a),numpy.rint(a),sep="\n")Approach 2. from numpy import * A = array([float(x) for x in input().split()],float) print(floor(A),ceil(A),rint(A),sep = '\n')Approach
Beeze Aal

Hackerrank Array Mathematics Solution

Basic mathematical functions operate element-wise on arrays. They are available both as operator overloads and as functions in the NumPy module. import numpy a = numpy.array([1,2,3,4], float) b = numpy.array([5,6,7,8], float) print a + b #[ 6. 8. 10. 12.] print numpy.add(a,
Beeze Aal

Hackerrank Shape and Reshape Solution

Solution in python3Approach 1. import numpy print( numpy.array(input().split(" "),int).reshape(3,3) )Approach 2. import numpy l=input().split() a=numpy.array(l,int) a.shape=(3,3) print(a)Approach 3. import numpy A = numpy.array(input().strip().split(),int) print(numpy.reshape(A,(3,3)