Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: mutliplying each element of a list by the same number

by moklevat (Priest)
on May 15, 2008 at 14:34 UTC ( [id://686737]=note: print w/replies, xml ) Need Help??


in reply to mutliplying each element of a list by the same number

PDL makes this operation trivial.
#!/usr/bin/perl use strict; use warnings; use PDL; my $max = $ARGV[0]; my $ratio_list = pdl (0..$max); my $minutes_list = 10 * $ratio_list;

Replies are listed 'Best First'.
Re^2: mutliplying each element of a list by the same number
by etj (Deacon) on Jun 06, 2022 at 02:42 UTC
    perl -MPDL -e '$n=shift; print +(sequence($n)+1)*$n'

    Turning the resulting ndarray into a flattened Perl list (with the list method) or structured Perl array (with the unpdl method) is left as an exercise for the reader.

Re^2: mutliplying each element of a list by the same number
by wade (Pilgrim) on May 15, 2008 at 17:52 UTC

    Kind-of seems to me like pounding a thumbtack with a sledgehammer. Of course, TIMTOWTDI

    --
    Wade
      Sure, but steph_bow asked for simple. It was simple to write and it's simple to read and it DWIM.
        yeah, but it's not necessarily simple to come up with. Sometimes it's actually more efficient (in terms of time, money, frustration or whatever) to work harder and not smarter.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://686737]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2024-03-28 19:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found