📘
Array-to-Array Operations
Problem Statement
Perform element-wise operations between two arrays.
Background
When arrays have the same shape, operations are element-wise:
arr1 + arr2 # Element-wise addition
arr1 * arr2 # Element-wise multiplication
Your Task
Write a function array_operations(arr1, arr2) that returns a dictionary with:
- "add": Element-wise addition as list
- "multiply": Element-wise multiplication as list
- "dot": Dot product (sum of element-wise multiplication)
Output Format
Return a dictionary with exactly these three keys.
Example:
Input:
arr1 = [1, 2, 3], arr2 = [4, 5, 6]
Output:
{'add': [5, 7, 9], 'multiply': [4, 10, 18], 'dot': 32}Reasoning:
add: [1+4, 2+5, 3+6], multiply: [14, 25, 3*6], dot: 4+10+18=32
Constraints:
- Both arrays will have the same shape
- Use np.dot() for dot product
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.