afalsename has asked for the wisdom of the Perl Monks concerning the following question:
I started programming with perl last week and perl is my first language so I'm a bit of a newbie. Basically I need help with a multidimensional array.
I have a 100k by 3 multidimensional array, contained in a CSV file. Each constituent array is a point in a 2D space with an intensity value taking up the third entry. But I need perl to calculate the norms of each constituent array and add those as a fourth column to this multidimensional array. So I would have a 100k by 4 multidimensional array.
Here's my code:sub norm{ $p=$#data; #I call the 100k x 3 array @data for($i=0;$i<=$p; $i++){ # iterates down @data $norm=(($data[$i][0])**2+($data[$i][1])**2)**(1/2); #calculate +s the norm push(@data[i],$norm); #pushes the norm into the correct row of + @data, yet I get an error. } }
Specifically my syntax checker tells me that the "Type of arg 1 to push must be array (not array slice) near "$norm)"
Aid me wise monks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: pushing multidimensional arrays
by ikegami (Patriarch) on Jul 05, 2010 at 20:17 UTC | |
|
Re: pushing multidimensional arrays
by moritz (Cardinal) on Jul 05, 2010 at 20:19 UTC | |
|
Re: pushing multidimensional arrays
by Anonymous Monk on Jul 05, 2010 at 20:12 UTC | |
|
Re: pushing multidimensional arrays
by roboticus (Chancellor) on Jul 06, 2010 at 11:21 UTC | |
|
Re: pushing multidimensional arrays
by punkish (Priest) on Jul 06, 2010 at 18:51 UTC | |
by etj (Priest) on May 29, 2022 at 22:11 UTC |