lc filter在matlab哪,MATLAB中“filter”对应的Python函数是什么?

要扩展@rayryeng的示例(奖金)答案:function out = filter_python(in, func)

out = in(func(in));

end

这种想法可以扩展到二维数组中的整行数据。在function out = filtrow(func,in,colnum)

if nargin == 2

colnum=0;

sz = size(in);

if sz(1)==1 || sz(2)==1

out = in(func(in));

return

else

out = in;

for i = sz(2):-1:1

out = out(func(out(:,i)),:);

end

end

end

if nargin == 3

out = in(func(in(:,colnum)),:);

end

或者如果你想喝可乐的话。在

^{pr2}$

所以给定矩阵A:A =

0 0.4694 0.1656 0.0838 0.0782 0.8687 0.1818

0.0540 0 0.6020 0.2290 0.4427 0.0844 0.2638

0.5308 0.3371 0 0.9133 0.1067 0.3998 0.1455

0.7792 0.1622 0.6541 0 0.9619 0.2599 0.1361

0.9340 0.7943 0.6892 0.8258 0.0046 0.8001 0.8693

0.1299 0.3112 0.7482 0.5383 0.7749 0.4314 0.5797

0.5688 0.5285 0.4505 0.9961 0.8173 0.9106 0.5499

#%%% We can also remove entire rows or cols by this method

#%%% here we use filtrow to remove rows where elements do no pass the c condition function

>> out = filtrow(@(x) x>0,A)

out =

0.9340 0.7943 0.6892 0.8258 0.0046 0.8001 0.8693

0.1299 0.3112 0.7482 0.5383 0.7749 0.4314 0.5797

0.5688 0.5285 0.4505 0.9961 0.8173 0.9106 0.5499

#%%% Or we can do the same to remove the cols

>> out = filtcol(@(x) x>0,A)

out =

0.0782 0.8687 0.1818

0.4427 0.0844 0.2638

0.1067 0.3998 0.1455

0.9619 0.2599 0.1361

0.0046 0.8001 0.8693

0.7749 0.4314 0.5797

0.8173 0.9106 0.5499

#%%%Or you could filter by individual rows

>> out = filtrow(@(x) x>0,A,1)

out =

0.0540 0 0.6020 0.2290 0.4427 0.0844 0.2638

0.5308 0.3371 0 0.9133 0.1067 0.3998 0.1455

0.7792 0.1622 0.6541 0 0.9619 0.2599 0.1361

0.9340 0.7943 0.6892 0.8258 0.0046 0.8001 0.8693

0.1299 0.3112 0.7482 0.5383 0.7749 0.4314 0.5797

0.5688 0.5285 0.4505 0.9961 0.8173 0.9106 0.5499

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值