我需要将下面显示的代码块转换为Python.我创建了两个名为
u
的数组
和
v
分别将它们放在for循环中,范围从0到M-1,我知道
find
与if条件类似.我有一个问题,因为两个
idx
和
u
是数组。
MATLAB代码是这样的:
u = 0:(M-1);
v = 0:(N-1);
idx = find(u > M/2);
u(idx) = u(idx) - M; #I have a problem here
idy = find(v > N/2);
v(idy) = v(idy) - N;
基本上,我在Python中所做的工作直到出现问题行为止:
input_image = Image.open('./....image....')
input_image=np.array(input_image)
M,N = input_image.shape[0],input_image.shape[1]
FT_img = fftpack.fftshift(fftpack.fft2(input_image))
# Assign the order value
n = 2; # one can change this value accordingly
# Assign Cut-off Frequency
D0 = 60; # one can change this value accordingly
# Designing filter
u=[]
v=[]
for i in range(M-1):
u.append(i)
for i in range(N-1):
v.append(i)
最新回答
- 2020-12-291 #
相关问题
- python:重复numpy数组的每个元素5次pythonarraysnumpyrepeat2021-01-11 22:25
- python:子集2D numpy数组pythonarraysnumpymultidimensionalarraysubset2021-01-11 01:28
- matlab:根据计数按元素进行数组复制arraysmatlabrepeatrunlengthencodingelementwiseoperations2021-01-10 21:55
您的MATLAB代码
通过省略find
可以更有效地实现:
这种形式可以通过NumPy轻松转换为Python: