From d6442d2004e0a75a639f0e5c32621b8bad4c158f Mon Sep 17 00:00:00 2001 From: Inessa Pawson Date: Sat, 28 Nov 2026 22:35:01 -0500 Subject: [PATCH] DOC: Add notes on sort, mgrid and fft differences to MATLAB users guide --- content/numpy-for-matlab-users.md | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/content/numpy-for-matlab-users.md b/content/numpy-for-matlab-users.md index 8dc5fca0..a0b99e28 100644 --- a/content/numpy-for-matlab-users.md +++ b/content/numpy-for-matlab-users.md @@ -399,7 +399,9 @@ arguments are two-dimensional entities. * - `[x,y]=meshgrid(0:8,0:5)` - `np.mgrid[0:9.,0:6.]` or `np.meshgrid(np.r_[0:9.],np.r_[0:6.])` - - two 2D arrays: one of x values, the other of y values + - two 2D arrays: one of x values, the other of y values. `np.meshgrid` + returns 6x9 arrays, like MATLAB. `np.mgrid` uses matrix (`'ij'`) + indexing, so it returns their 9x6 transposes, x values first. * - - `np.ogrid[0:9.,0:6.]` or `np.ix_(np.r_[0:9.],np.r_[0:6.])` @@ -523,19 +525,24 @@ arguments are two-dimensional entities. * - `fft(a)` - `np.fft.fft(a)` - - Fourier transform of `a` + - Fourier transform of `a`. For a 2D array, MATLAB transforms each + column, while NumPy transforms along the last axis (each row) by + default. Use `np.fft.fft(a, axis=0)` to match MATLAB. * - `ifft(a)` - `np.fft.ifft(a)` - - inverse Fourier transform of `a` + - inverse Fourier transform of `a`. As with `fft`, use + `np.fft.ifft(a, axis=0)` to match MATLAB for a 2D array. * - `sort(a)` - `np.sort(a, axis=0)` or `a.sort(axis=0)` - - sort each column of a 2D array, `a` + - sort each column of a 2D array, `a`. `np.sort` returns a sorted copy, + like MATLAB, while `a.sort` sorts `a` in place and returns `None`. * - `sort(a, 2)` - `np.sort(a, axis=1)` or `a.sort(axis=1)` - - sort the each row of 2D array, `a` + - sort each row of a 2D array, `a`. As above, `a.sort` sorts `a` in + place. * - `[b,I]=sortrows(a,1)` - `I = np.argsort(a[:, 0]); b = a[I,:]`