# [Numpy-discussion] For-less code

Gökhan Sever gokhansever@gmail....
Wed Feb 24 23:52:54 CST 2010

```Hello,

I am working on a code shown at

I use the code to analyse a couple dataset also placed in the same
directory. In the first part I use for-loops all over, but later decided to
write them without using for loops. The script runs correctly for the two
section, however I have a few question regarding to the for-less structures:

This part is taken after line 371:

gm10 = np.exp((1/Nt10)*(h10*np.log(Dp)).sum(axis=1))
gsd10 =
np.exp(((1/Nt10)*(h10*np.log(Dp/gm10[:,np.newaxis])**2).sum(axis=-1))**0.5)

dN_dDp10 =
(Nt10[:,np.newaxis]/((2*np.pi)**0.5*np.log(gsd10[:,np.newaxis])*d))*np.exp(-(np.log(d)-\

np.log(gm10[:,np.newaxis]))**2/(2*np.log(gsd10[:,np.newaxis])**2))

a10 = (dN_dDp10[0:300,d >= dc10u]*0.001).sum(axis=1)

Shape informations for the arrays as follow:

I[306]: gm10.shape; gsd10.shape, Dp.shape, d.shape, dN_dDp10.shape,
a10.shape
O[306]: (300,), (300,), (11,), (991,), (300, 991), (300,)

1-) In gsd10 line what does axis=-1 really means, and why negative axis
value is allowed?

2-) [:,np.newaxis] decreases the readability of the code. Is there any
alternative for it?

3-) In the last line (dN_dDp10[0:300,d >= dc10u]) could I achieve the same
result with different syntax? I have found it somewhat not in accordance
with the previous lines.