# Buggy code
def fit(self, x, y, batch_size=128, nb_epochs=10):
    """
    Fit the classifier on the training set `(x, y)`.

    :param x: Training data.
    :type x: `np.ndarray`
    :param y: Labels, one-vs-rest encoding.
    :type y: `np.ndarray`
    :param batch_size: Size of batches.
    :type batch_size: `int`
    :param nb_epochs: Number of epochs to use for trainings.
    :type nb_epochs: `int`
    :return: `None`
    """
    # Check if train and output_ph available
    if self._train is None or self._output_ph is None:
        raise ValueError(
            "Need the training objective and the output placeholder to train the model."
        )

    # Apply defences
    x_ = self._apply_processing(x)
    x_, y_ = self._apply_defences_fit(x_, y)

    num_batch = int(np.ceil(len(x_) / float(batch_size)))
    ind = np.arange(len(x_))

    # Start training
    for _ in range(nb_epochs):
        # Shuffle the examples
        random.shuffle(ind)

        # Train for one epoch
        for m in range(num_batch):
            i_batch = x_[ind[m * batch_size : (m + 1) * batch_size]]
            o_batch = y_[ind[m * batch_size : (m + 1) * batch_size]]

            # Run train step
            if self._learning is None:
                self._sess.run(
                    self._train,
                    feed_dict={self._input_ph: i_batch, self._output_ph: o_batch},
                )
            else:
                self._sess.run(
                    self._train,
                    feed_dict={
                        self._input_ph: i_batch,
                        self._output_ph: o_batch,
                        self._learning: True,
                    },
                )


# Traceback (IndexError)
Traceback (most recent call last):
File "cw_pytorch.py", line 172, in <module>
x_test_adv = cl2m.generate(inputs, **params)
File "/home/weitian/anaconda3/envs/xnor/lib/python3.6/site-packages/art/attacks/carlini.py", line 380, in generate
x_adv_batch_tanh[active_and_update_adv] = x_adv_batch_tanh[update_adv] + \
IndexError: boolean index did not match indexed array along dimension 0; dimension is 18 but corresponding boolean dimension is 17

# Fixed code
def fit(self, x, y, batch_size=128, nb_epochs=10):
    """
    Fit the classifier on the training set `(x, y)`.

    :param x: Training data.
    :type x: `np.ndarray`
    :param y: Labels, one-vs-rest encoding.
    :type y: `np.ndarray`
    :param batch_size: Size of batches.
    :type batch_size: `int`
    :param nb_epochs: Number of epochs to use for trainings.
    :type nb_epochs: `int`
    :return: `None`
    """
    # Check if train and output_ph available
    if self._train is None or self._output_ph is None:
        raise ValueError(
            "Need the training objective and the output placeholder to train the model."
        )

    # Apply defences
    x_ = self._apply_processing(x)
    x_, y_ = self._apply_defences_fit(x_, y)

    num_batch = int(np.ceil(len(x_) / float(batch_size)))
    ind = np.arange(len(x_))

    # Start training
    for _ in range(nb_epochs):
        # Shuffle the examples
        random.shuffle(ind)

        # Train for one epoch
        for m in range(num_batch):
            i_batch = x_[ind[m * batch_size : (m + 1) * batch_size]]
            o_batch = y_[ind[m * batch_size : (m + 1) * batch_size]]

            # Create feed_dict
            fd = {self._input_ph: i_batch, self._output_ph: o_batch}
            fd.update(self._feed_dict)

            # Run train step
            self._sess.run(self._train, feed_dict=fd)