[SciPy-user] Avoiding For Loops Question

josef.pktd@gmai... josef.pktd@gmai...
Fri Jun 5 12:58:34 CDT 2009

On Fri, Jun 5, 2009 at 1:48 PM, Whitcomb, Mr. Tim
<tim.whitcomb@nrlmry.navy.mil> wrote:
>> > I don't know what the style standard is regarding using the
>> colons to
>> > indicate entire arrays (i.e.
>> > a = x[:,numpy.newaxis] + y instead), but these should work for you.
>> so, in the examples above, I think, you can drop all [:], [:,:]
>> Josef
> You can indeed - I checked and made sure.  What is the generally
> accepted practice for their inclusion?  Sometimes in my Fortran code I
> use (:) to make it clear that these are array operations, but is the
> Numpy/Scipy convention to leave them out if they are not necessary?

On the left hand side they have different meaning, so it's important
to decide whether they are necessary or not.

On the right hand side, they are redundant and I didn't see much code
that would use them. Also, they restrict you in the shape of the array
that you can use in the expression, e.g. using [:,:] will raise an
exception if the array is only one dimensional and will have different
meaning if the array is 3d.
So to write flexible code it is better to leave them off if they are
not necessary.


More information about the SciPy-user mailing list