Founding Batch Offer ยท HLD ยท LLD ยท System Design at โ‚น799 until 30 Nov

Element-wise Product

Multiply corresponding values of two equal-sized lists. Students pair indexes, append products, and distinguish element-wise multiplication from list repetition.

IntermediatePhase 4 - Level 4: Aggregation & ComparisonExample 8 of 10
element-wise-product.py
1# Take arrays
2n = int(input("Enter array size: "))
3arr1 = []
4for i in range(n):
5 arr1.append(int(input(f"Array1 element {i+1}: ")))
6
7arr2 = []
8for i in range(n):
9 arr2.append(int(input(f"Array2 element {i+1}: ")))
10
11# Element-wise product
12product_arr = []
13for i in range(n):
14 product_arr.append(arr1[i] * arr2[i])
15
16print(f"Product array: {product_arr}")

Output

Enter array size: 3
Array1 element 1: 2
Array1 element 2: 3
Array1 element 3: 4
Array2 element 1: 5
Array2 element 2: 6
Array2 element 3: 7
Product array: [10, 18, 28]

In this one

  • Multiply corresponding entries
  • Keep products separate
  • Distinguish from a dot product

How it works

  1. 1

    Read equally sized lists.

  2. 2

    Append the product of each indexed pair.

  3. 3

    Print product_arr without summing its entries.

Edge cases

What happens for n = 0?

What happens for n = 0?

The product list is empty.

Are the products added afterward?

Are the products added afterward?

No. Each product remains a separate result entry.

What's going on

The same n controls input for both lists. The result loop multiplies arr1[i] by arr2[i] and appends that product.

For [2, 3] and [4, 5], the result is [8, 15]. This is neither a Cartesian product nor a dot-product total. The new list preserves positional pairing, and either zero factor makes its particular product zero.

What happens for n = 0? The product list is empty.

Are the products added afterward? No. Each product remains a separate result entry.

Quiz

Tap an option. The answer stays hidden until you pick.

Question 1

What is paired with arr1[i]?

Pick an answer to check it.

Question 2

What happens for n = 0?

Pick an answer to check it.

Questions people ask

What happens for n = 0?

The product list is empty.

Are the products added afterward?

No. Each product remains a separate result entry.

What is paired with arr1[i]?

arr2[i].