Write a NumPy program to convert a PIL Image into a NumPy array.
import numpy as np import PIL img_data = PIL.Image.open('w3resource-logo.png' ) img_arr = np.array(img_data) print(img_arr)
Sample Output:
[[[255 255 255 0] [255 255 255 0] [255 255 255 0] ... [255 255 255 0] [255 255 255 0] [255 255 255 0]] [[255 255 255 0] [255 255 255 0] [255 255 255 0] ... [255 255 255 0] [255 255 255 0] [255 255 255 0]] [[255 255 255 0] [255 255 255 0] [255 255 255 0] ... [255 255 255 0] [255 255 255 0] [255 255 255 0]] ... [[255 255 255 0] [255 255 255 0] [255 255 255 0] ... [255 255 255 0] [255 255 255 0] [255 255 255 0]] [[255 255 255 0] [255 255 255 0] [255 255 255 0] ... [255 255 255 0] [255 255 255 0] [255 255 255 0]] [[255 255 255 0] [255 255 255 0] [255 255 255 0] ... [255 255 255 0] [255 255 255 0] [255 255 255 0]]]
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer