title: Convert create.bspline.basis((rangval,nbasis,norder=norder,breaks=breaks) in R to BSpline(t, c, degree) in Python
body: <p>I am trying to convert the function <code>create.bspline.basis(rangval,nbasis,norder=norder,breaks=breaks)</code>  from R to Python.</p>
  <p>I have tried using the BSpline(t, c , degree) function from scipy.interpolate but cannot seem the get the same results as I got in R.</p>
  <p><strong>Here is my R code:</strong></p>
  <pre><code>library('fda')
  
  df &lt;- read.csv('data.csv', header = T)
  
  df &lt;- df[,1]        # convert data frame to vector. Vector has a length of 1941.
  
  rangval &lt;- c(1, length(df))
  
  breaks = seq(1,length(df),length.out=length(df)/60)
  
  norder = 6
  
  nbasis = length(breaks) - 2 + norder
  
  bbasis = create.bspline.basis(rangval,nbasis,norder=norder,breaks=breaks)
  
  plot(bbasis)
  </code></pre>
  <p><img src="https://i.stack.imgur.com/brtx9.png" alt="basis_plot" /></p>
  <p><strong>Here is my Python code:</strong></p>
  <p>from scipy.interpolate import BSpline</p>
  <p>import matplotlib.pyplot as plt</p>
  <p>import numpy as np</p>
  <p>import math</p>
  <h3>Load Data files as data frames:</h3>
  <p>df = pd.read_csv('RData\Data.csv')</p>
  <h3>Convert data frames to arrays:</h3>
  <p>df = df.to_numpy()</p>
  <p>breaks = np.linspace(1, (len(df)), math.ceil(len(df)/60))</p>
  <p>k = math.ceil(len(df)) - 2</p>
  <p>degree = 5</p>
  <p>order = degree + 1</p>
  <p>n = order + k</p>
  <p>t = np.zeros(math.ceil(len(df)/60) + (2*order)  # create an array to store knots.</p>
  <p>t[:order] = 0</p>
  <p>t[-:order] = len(df)</p>
  <p>t[order:-order] = (breaks)</p>
  <p>xx = np.arange(len(df))</p>
  <p>for i in range(0,n):</p>
  <pre><code>c = np.zeros(n)
  c[i] = 1
  spl = BSpline(t,c,degree)
  plt.plot(xx, spl(xx))
  </code></pre>
  <p>plt.show()</p>
  <p><strong>With the python code above I get the plot:</strong></p>
  <p><a href="https://i.stack.imgur.com/TqrGB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TqrGB.png" alt="enter image description here" /></a></p>
  <p>For my python code, I will like to have all the BSplines in a single object and not just be able to plot each BSpline one at a time. My goal is to use the full set of BSplines and it to pass it into another function to perform smoothing.</p>
  <p>Basically, I am trying to follow the steps below but using Python:</p>
  <p><a href="https://i.stack.imgur.com/MVH3X.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MVH3X.png" alt="enter image description here" /></a></p>