Element-wise Product
Calculate element-wise product of two arrays.
IntermediatePhase 4 - Level 4: Aggregation & ComparisonExample 8 of 10
element-wise-product.py
1# Take arrays2n = int(input("Enter array size: "))3arr1 = []4for i in range(n):5 arr1.append(int(input(f"Array1 element {i+1}: ")))67arr2 = []8for i in range(n):9 arr2.append(int(input(f"Array2 element {i+1}: ")))1011# Element-wise product12product_arr = []13for i in range(n):14 product_arr.append(arr1[i] * arr2[i])1516print(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]
What's going on
Multiply corresponding elements.
Key Concepts:
Arrays must be same size
Multiply arr1[i] * arr2[i]
Create new array
🔗Related Content
- 📖
Phase 4 - Learn Concepts
Review Phase 4 concepts and explanations
- 📝
Phase 4 - Quiz
Test your Phase 4 understanding with quiz questions
- 💻
Phase 4 - All Practice Problems
Explore all practice problems for Phase 4
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum