HackerRank Python Solution - Math Topic - Polar Coordinates

  • Polar coordinates are an alternative way of representing Cartesian coordinates or Complex Numbers.
  • A complex number z = x + yj,  is completely determined by its real part x and imaginary part y. Here, j is the imaginary unit. 
  • A polar coordinate (r,φ) is completely determined by modulus r and phase angle φ.
  • If we convert complex number z to its polar coordinate, we find:
    • r: Distance from to origin, i.e., √ (x^2 + y^2)
    • φ: Counterclockwise angle measured from the positive x-axis to the line segment that joins z to the origin. 
  •  Python's cmath module provides access to the mathematical functions for complex numbers.

HackerRank Python Solution - Numpy Topic - Linear Algebra

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.eig computes the eigenvalues and right eigenvectors of a square array.

HackerRank Python Solution - Numpy Topic - Polynomials

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.

HackerRank Python Solution - Numpy Topic - Inner and Outer

Inner:

The 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

HackerRank Python Solution - Numpy Topic - Dot and Cross

Dot:

The dot tool returns the dot product of two arrays.

import numpy

A = numpy.array([ 1, 2 ])
B = numpy.array([ 3, 4 ])

print numpy.dot(A, B)       #Output : 11

You might also like

Deploy your Django web app to Azure Web App using App Service - F1 free plan

In this post, we will look at how we can deploy our Django app using the Microsoft Azure app service - a free plan. You need an Azure accoun...