Login  Register

Re: Apply multiplication to all elements in an array

Posted by CARL Philippe (LBP) on Aug 31, 2017; 8:56am
URL: http://imagej.273.s1.nabble.com/Apply-multiplication-to-all-elements-in-an-array-tp5019299p5019302.html

Dear Kees and WJ,
I'm sorry to disturb, but I would rather do it this way:
a = newArray(0,1,2,3,4);
for (i=0; i<a.length; i++)
        a[i]*=5;
Array.print(a);
My best regards,
Philippe

-----Message d'origine-----
De : ImageJ Interest Group [mailto:[hidden email]] De la part de
Straatman, Kees (Dr.)
Envoyé : jeudi 31 août 2017 09:33
À : [hidden email]
Objet : Re: Apply multiplication to all elements in an array

Dear WJ,

Try

a = newArray(0,1,2,3,4);
b = newArray(5);
for (i=0; i<a.length; i++)
        b[i] = a[i]*5;
Array.print(b);

Best wishes

Kees


-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of
wei.jian
Sent: 31 August 2017 04:48
To: [hidden email]
Subject: Apply multiplication to all elements in an array

Hi there,

I'm new to coding and can someone guide or direct me to how I can multiply a
constant (say 5) to an array of elements:

For e.g. a = newArray(0,1,2,3,4);

I wish to get another array whereby: b = 0, 5, 10, 15, 20

Thanks.
WJ



--
Sent from: http://imagej.1557.x6.nabble.com/

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html