With `np.meshgrid`

numpy provides a convenient way of plotting functions of two variables, e.g. like so:

```
def plot():
fig = plt.figure()
ax = plt.axes(projection="3d")
x = np.linspace(-6, 6, 30)
y = np.linspace(-6, 6, 30)
X, Y = np.meshgrid(x, y)
Z = f(X, Y)
ax.plot_surface(X, Y, Z)
plt.show()
```

Unfortunately, this easy setup interferes with me defining any quadratic function

in the most natural numpy way, i.e. like so

```
def f(x, y):
vec_x = np.array([x, y])
return 1/2 * np.dot(vec_x.T, np.dot(A, vec_x)) - np.dot(b.T, vec_x)
```

The problem is that the `meshgrid`

arrays `X`

and `Y`

in `plot()`

when calling `Z = f(X, Y)`

will now be processed as arrays by the line `vec_x = np.array([x, y])`

which results in `vec_x`

being a `(2, 30, 30)`

shape array instead of an entry-by-entry treatment which would give a `(2,)`

shape array **which is what I would want**. Compare this to

```
def other_f(x, y):
return x + y
```

which works perfectly in a natural way with numpy thanks to the vectorization.

I haven't used numpy and matplotlib for a while but I would really and all workarounds that I come up with feel super clumsy, so, I'd love to see a neat way to work around this.

You could use `einsum`

like so:

```
np.einsum('i...,ij,j...',vec_x,A,vec_x)/2 - np.einsum('i...,i',vec_x,b)
```

This is interpreted by Einstein convention as:

```
1/2 sum_ij vecx_i,... A_ij vecx_j,... - sum_i vecx_i,... b_i
```

- How to merge keras sequential models with same input?
- Merge 2 sequential models in Keras
- requests.get(url).content is blank from 8a.nu
- Kivy text input and output
- keras load_model raise error when executed a second time
- keras load_model raise error when executed a second time
- How to set splash timeout in scrapy-splash?
- Python slicing and replacing
- Dataflow pipeline triggering NotImplementedError [while running 'Filter Status 1']
- Dataflow pipeline triggering NotImplementedError [while running 'Filter Status 1']

- Add –cleanup option to python3 -m test to remove `test_pyt
- thon version by running `python3` or whichever version you w
- unning: $ python -m zipapp myapp $ python
- s set up at https://bugs.python.org. One installation of Rou
- s set up at https://bugs.python.org. One installation of Rou
- thon 2.5 at https://docs.python.org. If you want to understa
- thon 2.5 at https://docs.python.org. If you want to understa
- ray type; see http://www.numpy.org/ for further information