1

I want to compute covariance using PDL, but the problem is that it always shows an error:

Undefined subroutine &main::cov called at line 12.

Can anyone tell me where I'm making a mistake?

#! usr/bin/perl

use strict;
use warnings;
use PDL;

my $a = random(5, 3);
my $b = random(5, 3);

print "$a\n$b\n";

my $cov = cov($a, $b);     #line 12

print "$cov\n";
0

1 Answer 1

2

That error message tells you that a function named cov is not exported by default by PDL. If I search the PDL CPAN page (using the grep tool), I do not see a function named cov.

A google search yields PDL::Stats::Basic, which has a cov function.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi, that worked. I thought that using PDL would import all the modules under it. I had to install this PDL::Stats::Basic module separately. And now it works!! Thanks!!
It looks like PDL::Stats is a completely separate distribution from PDL.
It is completely separate. PDL doesn't import everything "under it" because that would be a vast amount of code, and take ages to load. use PDL is documented as loading a specific set of modules: metacpan.org/pod/PDL#SYNOPSIS

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.