title: How to extract the BSpline basis from scipy.interpolate.BSpline
body: <p>In <a href="https://stackoverflow.com/questions/35236221/how-to-get-the-spline-basis-used-by-scipy-interpolate-splev">this question</a> I asked the community about how <code>scipy.interpolate.splev</code> calculates a spline basis.. My goal was to compute a spline faster then <code>splev</code> by pre-calculating a <code>bspline basis</code> and generate a curve by doing a <code>basis</code> to <code>control point</code> dot product.</p>
  
  <p>Since then <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.BSpline.html" rel="noreferrer">a new <code>scipy.interpolate.BSpline</code> interpolator</a> was added to <code>scipy</code>. <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.BSpline.basis_element.html#scipy.interpolate.BSpline.basis_element" rel="noreferrer">It comes with a <code>basis_element</code> function</a>, which I presume could be used to return the basis used to calculate a spline.</p>
  
  <p>So for example using the code <a href="https://stackoverflow.com/questions/35236221/how-to-get-the-spline-basis-used-by-scipy-interpolate-splev">from here</a> with the inputs below:</p>
  
  <pre><code>import numpy as np
  
  # Control points
  cv = np.array([[ 50.,  25., 0.],
         [ 59.,  12., 0.],
         [ 50.,  10., 0.],
         [ 57.,   2., 0.],
         [ 40.,   4., 0.],
         [ 40.,   14., 0.]])
  
  kv = [0, 0, 0, 0, 1, 2, 3, 3, 3, 3] # knot vector
  n = 10  # 10 samples (keeping it simple)
  degree = 3 # Curve degree
  </code></pre>
  
  <p>I can compute the following bspline basis:</p>
  
  <pre><code>[[ 1.          0.          0.          0.          0.          0.        ]
   [ 0.2962963   0.56481481  0.13271605  0.00617284  0.          0.        ]
   [ 0.03703704  0.51851852  0.39506173  0.04938272  0.          0.        ]
   [ 0.          0.25        0.58333333  0.16666667  0.          0.        ]
   [ 0.          0.07407407  0.54938272  0.36728395  0.00925926  0.        ]
   [ 0.          0.00925926  0.36728395  0.54938272  0.07407407  0.        ]
   [ 0.          0.          0.16666667  0.58333333  0.25        0.        ]
   [ 0.          0.          0.04938272  0.39506173  0.51851852  0.03703704]
   [ 0.          0.          0.00617284  0.13271605  0.56481481  0.2962963 ]
   [ 0.          0.          0.          0.          0.          1.        ]]
  </code></pre>
  
  <p>Using <code>np.dot</code> with <code>basis</code> and <code>control points</code> returns 10 samples on curve:</p>
  
  <pre><code>[[ 50.          25.           0.        ]
   [ 55.12654321  15.52469136   0.        ]
   [ 55.01234568  11.19753086   0.        ]
   [ 53.41666667   9.16666667   0.        ]
   [ 53.14506173   7.15432099   0.        ]
   [ 53.1882716    5.17901235   0.        ]
   [ 51.58333333   3.83333333   0.        ]
   [ 47.20987654   3.87654321   0.        ]
   [ 42.31790123   6.7345679    0.        ]
   [ 40.          14.           0.        ]]
  </code></pre>
  
  <p><strong>Question</strong> : is it possible to extract the basis as described above out of <code>scipy.interpolate.BSpline</code>? </p>
  
  <p>Obviously I must be using it wrong, because when I try I get something like this:</p>
  
  <pre><code>from scipy.interpolate import BSpline
  b = BSpline.basis_element(kv)
  print b(np.linspace(kv[0],kv[-1],n)) # i'm not sure what these values represent
  [ 0.          0.00256299  0.04495618  0.16555213  0.28691315  0.28691315
    0.16555213  0.04495618  0.00256299  0.        ]
  </code></pre>