# tf.keras.preprocessing.image.NumpyArrayIterator

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v2.7.0/keras/preprocessing/image.py#L413-L474) |

Iterator yielding data from a Numpy array.

Inherits From: [`Iterator`](https://www.tensorflow.org/versions/r2.7/api_docs/python/tf/keras/preprocessing/image/Iterator), [`Sequence`](https://www.tensorflow.org/versions/r2.7/api_docs/python/tf/keras/utils/Sequence)

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.keras.preprocessing.image.NumpyArrayIterator`](https://www.tensorflow.org/api_docs/python/tf/keras/preprocessing/image/NumpyArrayIterator)

<br />

    tf.keras.preprocessing.image.NumpyArrayIterator(
        x,
        y,
        image_data_generator,
        batch_size=32,
        shuffle=False,
        sample_weight=None,
        seed=None,
        data_format=None,
        save_to_dir=None,
        save_prefix='',
        save_format='png',
        subset=None,
        dtype=None
    )

<br />

<br />

<br />

| ## Args ||
|---|---|
| `x` | Numpy array of input data or tuple. If tuple, the second elements is either another numpy array or a list of numpy arrays, each of which gets passed through as an output without any modifications. |
| `y` | Numpy array of targets data. |
| `image_data_generator` | Instance of `ImageDataGenerator` to use for random transformations and normalization. |
| `batch_size` | Integer, size of a batch. |
| `shuffle` | Boolean, whether to shuffle the data between epochs. |
| `sample_weight` | Numpy array of sample weights. |
| `seed` | Random seed for data shuffling. |
| `data_format` | String, one of `channels_first`, `channels_last`. |
| `save_to_dir` | Optional directory where to save the pictures being yielded, in a viewable format. This is useful for visualizing the random transformations being applied, for debugging purposes. |
| `save_prefix` | String prefix to use for saving sample images (if `save_to_dir` is set). |
| `save_format` | Format to use for saving sample images (if `save_to_dir` is set). |
| `subset` | Subset of data (`"training"` or `"validation"`) if validation_split is set in ImageDataGenerator. |
| `dtype` | Dtype to use for the generated arrays. |

<br />

## Methods

### `next`

[View source](https://github.com/keras-team/keras-preprocessing/tree/1.1.2/keras_preprocessing/image/iterator.py#L106-L116)

    next()

For python 2.x.

<br />

<br />

<br />

| Returns ||
|---|---|
| The next batch. ||

<br />

### `on_epoch_end`

[View source](https://github.com/keras-team/keras-preprocessing/tree/1.1.2/keras_preprocessing/image/iterator.py#L70-L71)

    on_epoch_end()

### `reset`

[View source](https://github.com/keras-team/keras-preprocessing/tree/1.1.2/keras_preprocessing/image/iterator.py#L73-L74)

    reset()

### `__getitem__`

[View source](https://github.com/keras-team/keras-preprocessing/tree/1.1.2/keras_preprocessing/image/iterator.py#L52-L65)

    __getitem__(
        idx
    )

### `__iter__`

[View source](https://github.com/keras-team/keras-preprocessing/tree/1.1.2/keras_preprocessing/image/iterator.py#L98-L101)

    __iter__()

### `__len__`

[View source](https://github.com/keras-team/keras-preprocessing/tree/1.1.2/keras_preprocessing/image/iterator.py#L67-L68)

    __len__()

<br />

<br />

<br />

| ## Class Variables ||
|---|---|
| white_list_formats | `('png', 'jpg', 'jpeg', 'bmp', 'ppm', 'tif', 'tiff')` |

<br />