What do these lines of code do?
<p>I am working with <code>numpy</code>. I encountered this line of code. </p>

<pre><code>a = (1.,80.,5.)
</code></pre>

<p>What does this mean? At some other line, I found</p>

<pre><code>aList = np.arange(a[0], a[1]+a[2], a[2])
</code></pre>

<p><strong>Note:</strong> <code>np</code> is namespace assigned from <code>numpy</code>.</p>

<p><code>a</code> is a <em>tuple</em> of floats. A tuple is a kind of structure that is kinda like a <em>list</em>, but is <em>immutable</em> (i.e. you cannot modify any of its components once it has been created). But, like a list it can be indexed. </p>

<p>In theory, some tuples have special names, for example a tuple of 2 is called a pair, a tuple of 3 is called a triplet etc (people don't necessarily call them that, but it helps a bit more to understand what a tuple is about).
Because it's immutable, conceptually it is thought of more as a unique object, rather than as a collection of ones; for this reason it can also be validly used as a key to a dictionary (as opposed to lists which cannot).</p>

<p>To create a tuple, you create a comma-separated sequence of objects inside parentheses, i.e. <code>()</code> (as opposed to brackets, i.e. <code>[]</code> that you would to create a list).</p>

<p>As for floats, the float <code>3.0</code> can also be written <code>3.</code> for short.</p>

<p>The <code>numpy.arange</code> function then creates a range by calling it using the components of the tuple as arguments. In your particular case, it will create a range of numbers from 1 to 80+5, at increments of 5.</p>

<p>A very cool use of tuples is that they can be expanded into a sequence of arguments to a function. e.g. if you had a tuple <code>a = (1.,10.,2.)</code>, and you wanted to call <code>numpy.arange(a[0], a[1], a[2])</code>, you could just do <code>numpy.arange(*a)</code> instead.</p>

python numpy