title: Too many indices error, in my already micro dataset
body: <p>This is my small test CSV file, because I'm trying to isolate the error.</p>
  
  <pre><code>Destination Port    Flow Duration   Total Fwd Packets   Labels
  22  20  100 BENIGN
  21  30  200 BENIGN
  43  30  100 Bot
  15  11  203 Bot
  </code></pre>
  
  <p>So when I run the following code, to preprocess the data,</p>
  
  <pre><code>import csv
  # import itertools
  import os
  from os.path import join as os_join
  import numpy as np
  
  
  dataroot = r'D:\DDOS\testing_too_many_indices'
  
  attacks = {'BENIGN': 0, 'Bot': 1}
  # and many others
  
  features = ['Destination Port', 'Flow Duration', 'Total Fwd Packets']
  
  np.random.seed(1202)
  
  
  def get_filenames(a_dir):
      return [name for name in os.listdir(a_dir)
              if os.path.isfile(os.path.join(a_dir, name))]
  
  
  def read_csv(filename, sampling_rate=100):
      with open(filename) as csv_file:
          print('Reading {} ...'.format(filename))
          reader = csv.reader(csv_file)
          # header = next(reader)
          data = [row for row in reader]
          print('#{} rows read'.format(len(data)))
          N = len(data)
          sample_size = N*sampling_rate//100
          indices = np.random.randint(0, N, sample_size)
          sampled_data = [data[i] for i in indices]
      return sampled_data
  
  
  def read_data(dataroot, sampling_rate=10, seed=0):
      np.random.seed(seed)
      filenames = get_filenames(dataroot)
      data = []
      for filename in filenames:
          data_part = read_csv(os_join(dataroot, filename), sampling_rate)
          data += data_part
      return data
  
  
  data = read_data(dataroot, sampling_rate=10)
  
  arr = np.array(data)
  # X contains feature values and Y the output values.
  X = arr[:, :-1].astype(np.float32)  # ERROR HERE.
  Y_str = arr[:, -1]
  </code></pre>
  
  <p>I get the error as follows:-</p>
  
  <pre><code>File "/some_path/temp.py", line 63, in &lt;module&gt;
      X = arr[:, :-1].astype(np.float32)
  
  IndexError: too many indices for array
  </code></pre>
  
  <p>What should I do? I've wracked my brains on other possibly duplicate links like <a href="https://stackoverflow.com/questions/37163047/python-too-many-indices-for-array?rq=1">this one</a>, and <a href="https://stackoverflow.com/questions/14793585/indexerror-too-many-indices">this one</a>, etc. Also made the above sample snippet to test in isolation, read about <a href="https://machinelearningmastery.com/index-slice-reshape-numpy-arrays-machine-learning-python/" rel="nofollow noreferrer">2D slicing</a> and yet am clueless. Can you help me?</p>