From 23f378718ed93b9b8d9e51fe18f07a55f61dc9c1 Mon Sep 17 00:00:00 2001 From: Luis Mochan Date: Wed, 27 Dec 2023 14:54:57 -0600 Subject: New solution to PWC248-2 --- challenge-248/wlmb/perl/ch-2a.pl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 challenge-248/wlmb/perl/ch-2a.pl diff --git a/challenge-248/wlmb/perl/ch-2a.pl b/challenge-248/wlmb/perl/ch-2a.pl new file mode 100755 index 0000000000..f0dfe67719 --- /dev/null +++ b/challenge-248/wlmb/perl/ch-2a.pl @@ -0,0 +1,16 @@ +#!/usr/bin/env perl +use v5.36; +use PDL; +use PDL::Image2D; +die <<~"FIN" unless @ARGV==3; + Usage: $0 M W H + where M is a matrix "[[m11,m22...],[m21,m22....],...]" + and W and H are the size of a sliding window to make a matrix of HxW submatrices + and sum the submatrix matrix elements. + FIN +my $m=pdl(shift); +my $w=shift; +my $h=shift; +say "Input: $m Width $w, Height $h -> ", + $m->conv2d(ones($w,$h))->slice([floor(($w-1)/2),floor(-($w+1)/2)], + [floor(($h-1)/2),floor(-($h+1)/2)]); -- cgit