Algorithm


Problem Name: Python - Inner and Outer

Problem Link: https://www.hackerrank.com/challenges/np-inner-and-outer/problem?isFullScreen=true  

In this HackerRank Functions in PYTHON problem solution,

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

 

 

 

Code Examples

#1 Code Example with Python Programming

Code - Python Programming


import numpy

A = numpy.array([int(chr) for chr in input() if chr!= " " ])

B = numpy.array( [int(chr) for chr in input() if chr!= " " ])

print(numpy.inner(A,B))

print(numpy.outer(A,B))
Copy The Code & Try With Live Editor
Advertisements

Demonstration


Previous
[Solved] Dot and Cross in PYTHON solution in Hackerrank
Next
[Solved] Polynomials in PYTHON solution in Hackerrank