PY-85
Compute Weighted Scores and Show Contributions
Task
Write compute_weighted_scores(row, batch, weights). row is one finite
one-dimensional NumPy array of sensor values. batch is a finite two-
dimensional array whose columns have the same sensor order as row. weights
is a finite one-dimensional array with one value per sensor. The three arrays
must have matching sensor lengths; batch may have zero rows.
For every value and its same-position weight, define the contribution as
value * weight. A row score is the sum of its sensor contributions. Return a
dictionary with exactly these keys:
"row_contributions": an independentfloat64array with the contribution for each sensor inrow;"row_score": thefloatsum ofrow_contributions;"batch_contributions": an independentfloat64array with the same shape asbatch;"batch_scores": an independentfloat64array with one sum per batch row, reducing the sensor axis.
The batch and the single row use the same positional pairing. Do not add a bias, normalize the weights, or reorder sensors. Keep all inputs unchanged.
Example
With row=[2,-1,4], batch=[[2,-1,4],[0,3,-2]], and
weights=[0.5,2,-1], the row contributions are [1,-2,-4] and its score is
-5. The batch contributions are [[1,-2,-4],[0,6,2]], so batch scores are
[-5,8].
Your implementation
You may import NumPy as np. Do not modify an input, print, or ask for input.