1

Outer Product

Unsolved
Linear Algebra

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

Amazon
Google
Netflix

The outer product is an operator that takes you from one state to another. In linear algebra, the outer product of two coordinate vectors is a matrix. If the two vectors have dimensions n and m, then their outer product is an n × m matrix. 

                                                               \(\mathbf{v}=\left[\begin{array}{c} v_{1} \\ v_{2} \\ \vdots \\ v_{n} \end{array}\right], \mathbf{w}=\left[\begin{array}{c} w_{1} \\ w_{2} \\ \vdots \\ w_{m} \end{array}\right]\)

                         \(\underset{\underset{\scriptstyle\text{\bigotimes}}{\scriptstyle}}{\mathbf{v} \bigotimes \mathbf{w}} = \underset{\underset{\scriptstyle\text{\otimes}}{\scriptstyle}}{\mathbf{v} \otimes \mathbf{w}}=\left[\begin{array}{cccc} v_{1} w_{1} & v_{1} w_{2} & \cdots & v_{1} w_{m} \\ v_{2} w_{1} & v_{2} w_{2} & \cdots & v_{2} w_{m} \\ \vdots & \vdots & \ddots & \vdots \\ v_{n} w_{1} & v_{n} w_{2} & \cdots & v_{n} w_{m} \end{array}\right]\)

 

Your function will take two NumPy arrays and compute the outer product.

Sample Input:
<class 'numpy.ndarray'>
arr1: [8 8 3 7 7 0 4]
<class 'numpy.ndarray'>
arr2: [2 5 2 2 2 1 0]

Expected Output:
<class 'numpy.ndarray'>
[[16 40 16 16 16 8 0] [16 40 16 16 16 8 0] [ 6 15 6 6 6 3 0] [14 35 14 14 14 7 0] [14 35 14 14 14 7 0] [ 0 0 0 0 0 0 0] [ 8 20 8 8 8 4 0]]

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Molestiae tempore cum omnis ab quaerat tenetur velit iure vel cupiditate beatae, eum cupiditate alias tempora doloremque, nobis saepe obcaecati laborum fuga natus? Natus sint nihil eos, architecto cumque nulla repellendus culpa unde tempora quo at, debitis dolorum minus soluta accusantium exercitationem? Ipsam eligendi harum dolorem quisquam esse est quod ad et.

Eum voluptas animi, dicta sunt libero natus a, officia iusto adipisci, accusamus id soluta corrupti ducimus nostrum iste modi autem. Sequi tempora quidem nisi asperiores dolorem sint, recusandae repellat minima itaque at dicta reiciendis aut earum laudantium, hic laudantium molestiae expedita debitis repellat ea aliquid nobis exercitationem perferendis eius, quibusdam quam enim cum vel, laborum earum quam et rerum.

Aliquid amet in repellat doloribus iusto impedit error autem harum mollitia enim, corrupti voluptate illum dolor unde tenetur cupiditate, deleniti odit corrupti minus animi perspiciatis labore, praesentium perspiciatis magni saepe eum quos quaerat dolorum aperiam laudantium est? Voluptate et delectus aliquam reprehenderit asperiores recusandae libero facere dicta, saepe consequatur tempora voluptatum commodi incidunt repudiandae, vero tempora illum molestiae possimus ipsam? Excepturi molestiae consectetur odit deleniti commodi a amet dignissimos architecto, labore mollitia corporis, ab nemo quas aperiam nihil incidunt obcaecati culpa veritatis exercitationem facere, fugiat itaque laborum ullam autem veritatis molestias, asperiores nam aliquid vel omnis distinctio quam repellendus possimus qui ipsa fugiat.

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

Ready.

Input Test Case

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