title: Problem with reshaping dataset in NumPy in Python 3.9
body: <p>I'm new to data analysis, so I'm trying to understand the code. But I have a problem with this code:</p>
  <pre><code>def univariate_data(dataset, start_index, end_index, history_size, target_size):
      data = []
      labels = []
      start_index = start_index + history_size
      if end_index is None:
          end_index = len(dataset) - target_size
  
      for i in range(start_index, end_index):
          indices = range(i-history_size, i)
          # Reshape data from (history_size,) to (history_size, 1)
          data.append(np.reshape(dataset[indices], (history_size, 1)))
          labels.append(dataset[i+target_size])
      return np.array(data), np.array(labels)
  </code></pre>
  <p>History_size is the size of the last time interval, target_size is an argument that determines how far into the future the model should learn to predict. In other words, target_size is the target vector to be predicted.
  When I call this function like this:</p>
  <pre><code>univariate_past_history = 20
  univariate_future_target = 0
  TRAIN_SPLIT = 2000
  
  x_train_uni, y_train_uni = univariate_data(uni_data, 0, TRAIN_SPLIT,
                                             univariate_past_history,
                                             univariate_future_target)
  </code></pre>
  <p>I have the error:</p>
  <pre><code>---------------------------------------------------------------------------
  KeyError                                  Traceback (most recent call last)
  &lt;ipython-input-25-148d84980a5b&gt; in &lt;module&gt;()
        5 x_train_uni, y_train_uni = univariate_data(uni_data, 0, TRAIN_SPLIT,
        6                                            univariate_past_history,
  ----&gt; 7                                            univariate_future_target)
  
  &lt;ipython-input-23-74f4c24fbf96&gt; in univariate_data(dataset, start_index, end_index, history_size, target_size)
        9         indices = range(i-history_size, i)
       10         # Reshape data from (history_size,) to (history_size, 1)
  ---&gt; 11         data.append(np.reshape(dataset[indices], (history_size, 1)))
       12         labels.append(dataset[i+target_size])
       13     return np.array(data), np.array(labels)
  
  C:\Users\danil\.conda\envs\p35\lib\site-packages\pandas\core\series.py in __getitem__(self, key)
     1069         key = com.apply_if_callable(key, self)
     1070         try:
  -&gt; 1071             result = self.index.get_value(self, key)
     1072 
     1073             if not is_scalar(result):
  
  C:\Users\danil\.conda\envs\p35\lib\site-packages\pandas\core\indexes\base.py in get_value(self, series, key)
     4728         k = self._convert_scalar_indexer(k, kind=&quot;getitem&quot;)
     4729         try:
  -&gt; 4730             return self._engine.get_value(s, k, tz=getattr(series.dtype, &quot;tz&quot;, None))
     4731         except KeyError as e1:
     4732             if len(self) &gt; 0 and (self.holds_integer() or self.is_boolean()):
  
  pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()
  
  pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()
  
  pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
  
  pandas/_libs/index_class_helper.pxi in pandas._libs.index.Int64Engine._check_type()
  
  KeyError: range(0, 20)
  </code></pre>
  <p>Can someone help with this part of the code?
  How can I fix this error?</p>