79173465

Date: 2024-11-09 18:48:32
Score: 2
Natty:
Report link

If you can please provide context about the need for such a function I am happy to adjust my response but given your function I was able to simply the code to the following.

def docal2(a: np.array, b: np.array, d: np.array) -> np.array:
    r, c = a.shape
    sum_ = np.zeros(c, dtype=float)
    for i in range(r):
        sum_[0:d[i]] -= a[i, 0]
        sum_[d[i]] += b[i, 0]
        print(f"{sum_=}")
    return sum_

This should prevent unecessay slicing of your original data and speed up the computation significantly. If you can provide further context I am happy to help you even vectorize the calculation instead of raw iterations.

Few points:

Reasons:
  • RegEx Blacklisted phrase (2.5): please provide
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (0.5):
Posted by: anmol_gorakshakar