viored has asked for the wisdom of the Perl Monks concerning the following question:
Everything works fine, however, when I define a matrix like this$distmatrix=[[] , [0.25], [0.25,0.5], [1,0.75,0.75]]
then I have an error. Whats the difference between the two? I need to add to my distance matrix every time step as it grows, so defining the distance matrix explicitly doensn't look like an option.$main::hd=[[]]; $main::a = [0.25]; $main::b = [0.25,0.5]; $main::c = [1,0.75,0.75]; push @{main::hd}, [@main::a]; push @{main::hd}, [@main::b]; push @{main::hd}, [@main::c];
EDIT
I'm still at school, but I'll try your suggestions when I get home. The code I'm using does have strict on, but the error is with two modules that I'm using, or rather, the input I'm giving the module isn't what it expects (evidenced by a croak statement) When I run the following codeI get the error "memory allocation failure in treecluster" Which, after I read the module code comes from a croak statement if "!distmatrix" which I'm guessing means that if I input something that's not the correct kind of matrix, then it can't work. However, If I use the code#!/usr/bin/perl #ex2 use warnings; use strict; sub clust; $main::hd=[[]]; $main::a = [0.25]; $main::b = [0.25,0.5]; $main::c = [1,0.75,0.75]; push @{main::hd}, [@main::a]; push @{main::hd}, [@main::b]; push @{main::hd}, [@main::c]; $main::hdt = 0.4; &clust; for ($loop::i=0; $loop::i<=3; $loop::i++) { print $clust::cluster_ids->[$loop::i], "\n"; } sub clust { use Algorithm::Cluster::Thresh; use Algorithm::Cluster qw/treecluster/; $clust::tree = treecluster(data=>$main::hd, method=>'a'); $clust::cluster_ids = $clust::tree->cutthresh($main::hdt); }
I get the desired output#!/usr/bin/perl #ex2 use warnings; use strict; sub clust; $main::hd=[[] , [0.25], [0.25,0.5], [1,0.75,0.75]]; $main::hdt = 0.4; &clust; for ($loop::i=0; $loop::i<=3; $loop::i++) { print $clust::cluster_ids->[$loop::i], "\n"; } sub clust { use Algorithm::Cluster::Thresh; use Algorithm::Cluster qw/treecluster/; $clust::tree = treecluster(data=>$main::hd, method=>'a'); $clust::cluster_ids = $clust::tree->cutthresh($main::hdt); }
Sorry for being so vague, and I'll try your solutions tonight when I get home.1 1 1 0
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Arrays and Push
by fullermd (Vicar) on Apr 03, 2014 at 04:54 UTC | |
by boftx (Deacon) on Apr 03, 2014 at 05:28 UTC | |
by fullermd (Vicar) on Apr 03, 2014 at 07:21 UTC | |
|
Re: Arrays and Push
by boftx (Deacon) on Apr 03, 2014 at 04:49 UTC | |
|
Re: Arrays and Push
by bigj (Monk) on Apr 03, 2014 at 05:09 UTC | |
by boftx (Deacon) on Apr 03, 2014 at 05:35 UTC |