 
 
 
 
 
 
Re: filling in an array
- To: mathgroup at smc.vnet.net
- Subject: [mg55357] Re: filling in an array
- From: Jon Harrop <usenet at jdh30.plus.com>
- Date: Sun, 20 Mar 2005 04:11:49 -0500 (EST)
- References: <d1guie$sc$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
dumb_founded wrote:
> How can I input values into an array most efficiently?  I tried the
> code below, but it doesn't work.  The kernel starts working through the
> loop and never gets out.
> 
> Array[b, 10];
> For[i = 1, i = 10, b[i] = i/10]
Try using a functional style:
In[1]:= Function[{i},i/10] /@ Range[10]
         1   1  3   2  1  3  7   4  9
Out[1]= {--, -, --, -, -, -, --, -, --, 1}
         10  5  10  5  2  5  10  5  10
This maps the function "i -> i/10" over the Mathematica list "1..10".
The function can be written in Mathematica's elegant short-hand:
In[1]:= #/10& /@ Range[10]
Try to avoid programming styles used in imperative languages (such as C),
particularly constructs like "Do" and "For".
-- 
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com

