0

Is there a fast numpy way of quickly doing the following:

x = np.array([0,1,2,3,4]) # a 
y = np.array([10,20])

# x - y = np.array([[10, 20],[9,19],[8,18],[7,17],[6,16]]) # 5x2 matrix

Where the result would be the absolute difference between each element in x minus each element in y

kPow989
  • 426
  • 5
  • 22

1 Answers1

0

Yes there is, its down to how you build your array containing the result...

import numpy as np

x = np.array([0,1,2,3,4]) 
y = np.array([10,20])
z = np.array([y[0]-x[:], y[1]-x[:]])
zT = np.transpose(z)
DrBwts
  • 3,470
  • 6
  • 38
  • 62