title: TypeError: 'float' object is not subscriptable (Python)
body: <p>I have a project where I want to compute Bézier curves in order to approximate the 3d shape of a rear-view mirror. Basically, my idea is to start off some control points that will give me N points of a first Bézier curve B0, then reduce this curve by a coefficient C (0 &lt; C &lt; 1) so that I have a smaller curve B1 whose barycenter is the same as B0. Then I would place both curve at a predetermined heights (h for B1 and 0 for B0) by going from 2d to 3d. I already coded it and it looks like this:</p>
  
  <p><img src="https://i.stack.imgur.com/IE4qS.png" alt="2d Bézier curves in 3d"></p>
  
  <p>So now I would like to draw the curvy lines that will connect every point of the first curve B0 to the reduced curve B1, and make the whole thing look more or less like a rear-view mirror. To do so, I considered that since the distance between every corresponding points on B0 and B1 is always the same, I could just use a bijection f that will connect each of these points. Now the curve of this bijection could be approximated by stacking m (m € |N*) intermediary curves (these curves wouldn't appear in the final plot) with decreasing reduction coefficients obtained with f.</p>
  
  <p>(Sidenote: I know using Poly3dCollection would give me a way better result, but I already tried it and it didn't work, apparently because of side effects I wasn't able to understand)</p>
  
  <p>But there is an error in this section of the code:</p>
  
  <pre><code>B= [B0]
  B += [bezier_reduit(pts, N, d*(m - phi)/m) for phi in F if (phi != 0) if (phi != d)]
  B += B1
  for j in range(N+1):        
      ax.plot([B[i][j][0] for i in range(m+1)], [B[i][j][1] for j in range(m+1)], F)
  </code></pre>
  
  <p>I represent points as lists of 2 floats [x,y], so Bézier curves like B0 and B1 are lists of lists of floats and B is a list of Bézier curves, so it is a list of lists of lists of floats. F is a list of floats that gives the z coordinate of each point. This section of the code is supposed to plot every line between two consecutive curves, so that in the end it looks more or less like the function f connecting B0 and B1.</p>
  
  <p>But when I try to execute the big function (Only showed part of it here to go directly to the point), it says this:</p>
  
  <pre><code>Traceback (most recent call last):
  File "&lt;console&gt;", line 1, in &lt;module&gt;
  File "F:\TIPE\Programmes\Programme final\bezier.py", line 157, in retro_line
  ax.plot([B[i][j][0] for i in range(m+1)], [B[i][j][1] for i in range(m+1)], F)
  File "F:\TIPE\Programmes\Programme final\bezier.py", line 157, in &lt;listcomp&gt;
  ax.plot([B[i][j][0] for i in range(m+1)], [B[i][j][1] for i in range(m+1)], F)
  TypeError: 'float' object is not subscriptable
  </code></pre>
  
  <p>So I looked it up online and I saw that apparently, this happens when a float is mistaken as a list, so for instance when something like x[0] with x a float is typed because Python can't reach the "first element" of a float. But I checked my code many times and I can't see where I did such a thing, so I don't really know where the error comes from.</p>
  
  <p>Edit : I checked the type of B, B[0], B[0][0] and B[0][0][0] (so I can be sure this values actually exist) using print(type(x)) and respectively got this:</p>
  
  <pre><code>&lt;class 'list'&gt;
  &lt;class 'list'&gt;
  &lt;class 'list'&gt;
  &lt;class 'float'&gt;
  </code></pre>
  
  <p>This matches what I was expecting, so unfortunately I still don't know where the error comes from.</p>