1

Kronecker Product

Unsolved
Linear Algebra

Difficulty: 3 | Problem written by Mr. Umair
Problem reported in interviews at

Amazon
Apple
Facebook
Google
Netflix

The Kronecker Product is a tensor product in matrix which can be calculated from vectors or matrices by generalizing the concept of the outer product. Given two 2D NumPy array, your function should return a 2D array containing the Kronecker Product.

Input:

Matrix A = [[0, 1, 2],[3, 4, 5],[6, 7,8]]

Matrix B = [[85, 77, 30], [ 2,  9, 34], [22, 14, 96]]

Output:

Resultant Matrix =  [[0, 0, 0, 0, 0, 0, 0, 0, 0],

                                 [0, 0, 0, 0, 22, 44, 0, 0, 0],

                                 [0, 255, 6, 66, 88, 110, 0, 0, 0],

                                 [0, 510, 12, 132, 154, 176, 0, 0, 0],

                                 [0, 462, 54, 84, 98, 112, 0, 0, 0],

                                 [0, 180, 204, 576, 672, 768, 0, 0, 0],

                                 [0, 0, 0, 0, 0, 0, 0, 0, 0],

                                 [0, 0, 0, 0, 0, 0, 0, 0, 0],

                                 [0, 0, 0, 0, 0, 0, 0, 0, 0]]

Sample Input:
<class 'list'>
A: [[0, 1, 2], [3, 4, 5], [6, 7, 8]]
<class 'list'>
B: [[85, 77, 30], [2, 9, 34], [22, 14, 96]]

Expected Output:
<class 'numpy.ndarray'>
[[ 0 0 0 85 77 30 170 154 60] [ 0 0 0 2 9 34 4 18 68] [ 0 0 0 22 14 96 44 28 192] [255 231 90 340 308 120 425 385 150] [ 6 27 102 8 36 136 10 45 170] [ 66 42 288 88 56 384 110 70 480] [510 462 180 595 539 210 680 616 240] [ 12 54 204 14 63 238 16 72 272] [132 84 576 154 98 672 176 112 768]]

This is a premium problem, to view more details of this problem please sign up for MLPro Premium. MLPro premium offers access to actual machine learning and data science interview questions and coding challenges commonly asked at tech companies all over the world

MLPro Premium also allows you to access all our high quality MCQs which are not available on the free tier.

Not able to solve a problem? MLPro premium brings you access to solutions for all problems available on MLPro

Get access to Premium only exclusive educational content available to only Premium users.

Have an issue, the MLPro support team is available 24X7 to Premium users.

This is a premium feature.
To access this and other such features, click on upgrade below.

Log in to post a comment

Comments
Ready.

Input Test Case

Please enter only one test case at a time
numpy has been already imported as np (import numpy as np)