You want to get rid of those `for`

loops. Try this:

```
def exampleKernelA(M, x, N, y):
"""Example kernel function A"""
i, j = np.indices((N, M))
# Define the custom kernel function here
kernel[i, j] = np.sqrt((x[i, 0] - y[j, 0]) ** 2 + (x[i, 1] - y[j, 1]) ** 2)
return kernel
```

You can also do it with broadcasting, which may be even faster, but a little less intuitive coming from `MATLAB`

.

### Related Contents:

- Most efficient way to map function over numpy array
- Performance of Pandas apply vs np.vectorize to create new column from existing columns
- numpy: most efficient frequency counts for unique values in an array
- Why is numpy’s einsum faster than numpy’s built in functions?
- Roll rows of a matrix independently
- Numpy sum elements in array based on its value
- Frequency counts for unique values in a NumPy array
- find length of sequences of identical values in a numpy array (run length encoding)
- Efficiently return the index of the first value satisfying condition in array
- A tool to convert MATLAB code to Python [closed]
- Link ATLAS/MKL to an installed Numpy
- Bin elements per row – Vectorized 2D Bincount for NumPy
- Fastest way to grow a numpy numeric array
- Vectorized searchsorted numpy
- Implement MATLAB’s im2col ‘sliding’ in Python
- Python’s sum vs. NumPy’s numpy.sum
- Numpy: Fix array with rows of different lengths by filling the empty elements with zeros
- Most efficient way to forward-fill NaN values in numpy array
- Why “numpy.any” has no short-circuit mechanism?
- How can I efficiently process a numpy array in blocks similar to Matlab’s blkproc (blockproc) function
- Pandas pd.Series.isin performance with set versus array
- Why is numpy.array so slow?
- Are NumPy’s math functions faster than Python’s?
- Efficiently detect sign-changes in python
- Efficient evaluation of a function at every cell of a NumPy array
- Why does numpy std() give a different result to matlab std()?
- Fastest save and load options for a numpy array
- Efficiently Calculating a Euclidean Distance Matrix Using Numpy
- Vectorizing Haversine distance calculation in Python
- Numpy and line intersections
- Python equivalent of MATLAB’s “ismember” function
- why isn’t numpy.mean multithreaded?
- What is the equivalent of MATLAB’s repmat in NumPy
- Why is `np.sum(range(N))` very slow?
- Efficient way to take the minimum/maximum n values and indices from a matrix using NumPy
- Why is a `for` over a Python list faster than over a Numpy array?
- Why list comprehension is much faster than numpy for multiplying arrays?
- No speedup when summing uint16 vs uint64 arrays with NumPy?
- Why does numpy.histogram (Python) leave off one element as compared to hist in Matlab?
- reading v 7.3 mat file in python
- “Converting” Numpy arrays to Matlab and vice versa
- Numpy loading csv TOO slow compared to Matlab
- Efficiently replace elements in array based on dictionary – NumPy / Python
- Why is Numpy much faster at creating a Zero array compared to replacing the values of an existing array with zeros?
- Selecting close matches from one array based on another reference array
- read matlab v7.3 file into python list of numpy arrays via h5py
- numpy float: 10x slower than builtin in arithmetic operations?
- Counting Cars OpenCV + Python Issue
- Performance with global variables vs local
- interpolate 3D volume with numpy and or scipy