title: Python TypeError: 'float' object cannot be interpreted as an index
body: <p>The following code uses audio files to create a matrix of features in <code>tensorflow</code>:</p>
  
  <pre><code>import tensorflow as tf
  
  directory = "audio_dataset/*.wav"
  
  filenames = tf.train.match_filenames_once(directory)
  
  init = (tf.global_variables_initializer(), tf.local_variables_initializer())
  
  count_num_files = tf.size(filenames)
  filename_queue = tf.train.string_input_producer(filenames)
  reader = tf.WholeFileReader()
  filename, file_contents = reader.read(filename_queue)
  
  with tf.Session() as sess:
      sess.run(init)
      num_files = sess.run(count_num_files)
  
      coord = tf.train.Coordinator()
      threads = tf.train.start_queue_runners(coord=coord)
  
      for i in range(num_files):
          audio_file = sess.run(filename)
          print(audio_file)
  </code></pre>
  
  <p>this is a toolkit that converts audio from time to frequency domain:    </p>
  
  <pre><code>from bregman.suite import *
  
  
  chromo = tf.placeholder(tf.float32)
  max_freqs = tf.argmax(chromo, 0)
  
  
  def get_next_chromogram(sess):
      audio_file = sess.run(filename)
      F = Chromagram(audio_file, nfft=16384, wfft=8192, nhop=2205)
      return F.X
  
  
  def extract_feature_vector(sess, chromo_data):
      num_features, num_samples = np.shape(chromo_data)
      freq_vals = sess.run(max_freqs, feed_dict={chromo: chromo_data})
      hist, bins = np.histogram(freq_vals, bins=range(num_features + 1))
      return hist.astype(float) / num_samples
  
  
  def get_dataset(sess):
      num_files = sess.run(count_num_files)
      coord = tf.train.Coordinator()
      threads = tf.train.start_queue_runners(coord=coord)
      xs = []
      for _ in range(num_files):
          chromo_data = get_next_chromogram(sess)
          x = [extract_feature_vector(sess, chromo_data)]
          x = np.matrix(x)
          if len(xs) == 0:
              xs = x
          else:
              xs = np.vstack((xs, x))
      return xs
  </code></pre>
  
  <p>this clusters the data around two centroids:    </p>
  
  <pre><code>k = 2
  max_iterations = 100
  
  def initial_cluster_centroids(X, k):
      return X[0:k, :]
  
  def assign_cluster(X, centroids):
      expanded_vectors = tf.expand_dims(X, 0)
      expanded_centroids = tf.expand_dims(centroids, 1)
      distances = tf.reduce_sum(tf.square(tf.subtract(expanded_vectors, expanded_centroids)), 2)
      mins = tf.argmin(distances, 0)
      return mins
  
  def recompute_centroids(X, Y):
      sums = tf.unsorted_segment_sum(X, Y, k)
      counts = tf.unsorted_segment_sum(tf.ones_like(X), Y, k)
      return sums / counts
  
  with tf.Session() as sess:
      sess.run(init)
      X = get_dataset(sess)
      centroids = initial_cluster_centroids(X, k)
      i, converged = 0, False
      while not converged and i &lt; max_iterations:
          i += 1
          Y = assign_cluster(X, centroids)
          centroids = sess.run(recompute_centroids(X, Y))
      print(centroids)
  </code></pre>
  
  <p>but Im getting the following traceback:</p>
  
  <pre><code>Traceback (most recent call last):
    File "components.py", line 776, in &lt;module&gt;
      X = get_dataset(sess)
    File "ccomponents.py", line 745, in get_dataset
      chromo_data = get_next_chromogram(sess)
    File "coffee_components.py", line 728, in get_next_chromogram
      F = Chromagram(audio_file, nfft=16384, wfft=8192, nhop=2205)
    File "/Volumes/Dados/Documents/Education/Programming/Machine Learning/Manning/book/BregmanToolkit-master/bregman/features.py", line 143, in __init__
      Features.__init__(self, arg, feature_params)
    File "/Volumes/Dados/Documents/Education/Programming/Machine Learning/Manning/book/BregmanToolkit-master/bregman/features_base.py", line 70, in __init__
      self.extract()
    File "/Volumes/Dados/Documents/Education/Programming/Machine Learning/Manning/book/BregmanToolkit-master/bregman/features_base.py", line 213, in extract
      self.extract_funs.get(f, self._extract_error)()
    File "/Volumes/Dados/Documents/Education/Programming/Machine Learning/Manning/book/BregmanToolkit-master/bregman/features_base.py", line 711, in _chroma
      if not self._cqft():
    File "/Volumes/Dados/Documents/Education/Programming/Machine Learning/Manning/book/BregmanToolkit-master/bregman/features_base.py", line 588, in _cqft
      self._make_log_freq_map()
    File "/Volumes/Dados/Documents/Education/Programming/Machine Learning/Manning/book/BregmanToolkit-master/bregman/features_base.py", line 353, in _make_log_freq_map
      mxnorm = P.empty(self._cqtN) # Normalization coefficients        
  TypeError: 'float' object cannot be interpreted as an index
  </code></pre>
  
  <p>as far as I'm concerned, <code>range</code>is an <code>int</code>and not a <code>float</code>.</p>
  
  <p>could someone please point me the error here?</p>