Consider the following code.
import numpy as np
def f(x, y):
return (x[:, np.newaxis] - y[:]).sum(axis = 1)
x1 = np.linspace(1, 2, 5)
y1 = np.linspace(3, 4, 7)
print(f(x1, y1))
# x2 = 2. # (won't work)
# x2 = [2.] # (won't work either)
x2 = np.asarray([2.])
print(f(x2, y1))
# x3, _ = np.meshgrid(x1, x1) # won't work
# print(f(x3, y1))
The first call f(x1, y1) works as expected.
The second call, the float needs to be "converted" before it works (I'd like the conversion to be transparent for users, so the conversion should be included in the definition of the function).
The third call does not work at all and I don't know how to tune the definition of the function so that it does the same as the first call but for some points on a grid.
Any ideas? Thanks.