lobs has asked for the wisdom of the Perl Monks concerning the following question:
Then add the hash into an array of documents as follows:while ($element = shift(@numOfWordArr)) { $termsFreq{$element} ++; if(!exists($docTerms{$element})) { $docTerms{$element}++; } }
Finally pass the array into an array to seperate the classes of the documents:push(@docArray, \%termsFreq);
took the advice from another thread to iterate through the arrays to get a hash value and print the doc matrix to a csv file:push(@classArr, \@docArray);
My problem is that I get rows of the same value since it is accessing the same hash per iteration. Help is much appreciated. Thanks!foreach my $subArr_ref(@classArr) { print "subArr_ref: ".@{$subArr_ref}."\n"; foreach my $hashRef(@{$subArr_ref}) { print "hashRef: ".$hashRef."\n"; foreach my $key (sort keys %{$hashRef}) { #print $csv $key.":".$hashRef->{$key}.","; print $csv "$key : ${$hashRef}{$key},"; } # foreach my $feat(@featureVector) { # print $csv $hashRef->{$feat}.","; # } print $csv $i."\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Creating CSV term document matrix from a hash stored in multideminsional array
by stevieb (Canon) on Mar 03, 2017 at 19:13 UTC | |
by lobs (Acolyte) on Mar 03, 2017 at 20:02 UTC | |
by stevieb (Canon) on Mar 03, 2017 at 20:06 UTC | |
by lobs (Acolyte) on Mar 04, 2017 at 01:21 UTC | |
by AnomalousMonk (Archbishop) on Mar 04, 2017 at 03:03 UTC | |
|
Re: Creating CSV term document matrix from a hash stored in multideminsional array
by Cow1337killr (Monk) on Mar 03, 2017 at 21:27 UTC |