# tf.keras.preprocessing.image.img_to_array

<br />

|---|---|
| [![](https://www.tensorflow.org/images/tf_logo_32px.png) TensorFlow 1 version](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/keras/preprocessing/image/img_to_array) | [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/keras/preprocessing/image.py#L77-L101) |

Converts a PIL Image instance to a Numpy array.

#### View aliases


**Compat aliases for migration**

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

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

<br />

    tf.keras.preprocessing.image.img_to_array(
        img, data_format=None, dtype=None
    )

<br />

<br />

<br />

| ## Arguments ||
|---|---|
| `img` | PIL Image instance. |
| `data_format` | Image data format, either "channels_first" or "channels_last". |
| `dtype` | Dtype to use for the returned array. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A 3D Numpy array. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | if invalid `img` or `data_format` is passed. |

<br />