I am attempting to translate the following Matlab code into python
d=real(ifft(fft(fw).*conj(fft(rv))))
d=[d(ld+1:length(d)) d(1:ld)]'
but the problem occurs in the following line of code:
ld=length(d)
My question is about the length function in matlab. How do I translate this correctly to python, to get an integer? I have tried np.size(d,1)
and np.prod(d.shape)
. But both of these return a ‘list’ and not a integer. Is there an easier way on how to do this?
Advertisement
Answer
As length
in Matlab return the maximum length of the matrix among its dimensions, if d
is a numpy array in python you can write:
ld = max(d.shape)
For example, if d
has (10, 30, 20)
dimension, the value of ld
will be 30
.