np.fft.fft
computes the one-dimensional discrete Fourier transform. If you give a one dimensional input (a vector), it will just compute the transform for that input. However, if your input has more than one dimension, like a 2D matrix, or higher, NumPy assumes you are giving many vectors and you want to compute the transform of each of them. The axis
parameter indicates the dimension corresponding to those vectors, and by default it is the last one (-1
). So, for example, for a 2D matrix m
, if axis=0
then each column m[:, 0]
, m[:, 1]
, etc. would be the vectors for which the transform is computed, while passing axis=1
(equivalent to the default axis=-1
), each row m[0, :]
, m[1, :]
, etc. would be considered a vector for the transform. If you want to compute the transform of all values in the input, regardless of the dimensions, you would have to flatten the input, for example with np.ravel
.
Btw, this is a very common convention in NumPy (and many other algebra packages), where a one-dimensional operation can work on multidimensional inputs by receiving an axis
parameter that indicates the dimension over which the operation is performed.