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
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 are given two arrays: A and B. Your task is to compute their inner and outer product.

Input Format:

The first line contains the space-separated elements of array A. The second line contains the space-separated elements of array B.
Output Format:
  • First, print the inner product. 
  • Second, print the outer product.
Sample Input:

0 1
2 3
Sample Output:

3
[[0 0]
 [2 3]]
Solution:

import numpy

A = numpy.array(input().split(),int)

B = numpy.array(input().split(),int)

print(numpy.inner(A,B))
print(numpy.outer(A,B))
Disclaimer: The problem statement is given by hackerrank.com but the solution is generated by the Geek4Tutorial admin. If there is any concern regarding this post or website, please contact us using the contact form. Thank you!

No comments:

Post a Comment

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...