我尝试在PDL矩阵或Vector数组上制作一个grep:
我的@toto;推(@toto,pdl(1,2,3));推(@toto,pdl(4,5,6));我的$ titi = pdl(1,2,3);print(“OK”)if(grep {$ _ eq $ titi} @toto);我也 …
免责声明:我对PDL一无所知。我已经阅读了这个消息来源。
有一个功能 PDL::all() 您可以与重载的比较运算符一起使用 == 。
PDL::all()
==
use PDL; my $foo = pdl(1,2,3); my $bar = pdl(4,5,6); my $qrr = pdl(1,2,3); print "OK 1" if PDL::all( $foo == $bar ); print "OK 2" if PDL::all( $foo == $qrr );
我还在寻找文档。
您可以使用 eq_pdl 从 Test::PDL :
eq_pdl
Test::PDL
use PDL; use Test::PDL qw( eq_pdl ); my @toto; push(@toto, pdl(1,2,3)); push(@toto, pdl(4,5,6)); my $titi = pdl(4,5,6); print("OK\n") if (grep { eq_pdl( $_, $titi) } @toto);
的 产量 强> :
OK