NumPy add output from np.dot or np.multiply to existing array

Viewed 1022

In NumPy, it's possible to specify an argument to np.dot and np.multiply called out, so that they won't create a new array when returning the result. However, in my use case, I need to compute the following:

  1. c = c + np.dot(a, b) # where a and b are matrices of shape n x m, and m x p
  2. c = c + np.multiply(a, b) # where a and b are matrices of equal shape n x m

Is there a way to do this without creating a new array each time? For example, something like this:

  1. np.dot(a, b, add_to=c)
  2. np.multiply(a, b, add_to=c)
1 Answers
Related