w3resource

NumPy: Create a white image of size 512x256

NumPy: Array Object Exercise-161 with Solution

Write a NumPy program to create a white image of size 512x256.

Sample Solution:

Python Code:

from PIL import Image
import numpy as np

a = np.full((512, 256, 3), 255, dtype=np.uint8)
image = Image.fromarray(a, "RGB")
image.save("white.png", "PNG")

Sample Output:

NumPy array: Create a white image of size 512x256

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a NumPy program to find the k smallest values of a given numpy array.
Next: Write a NumPy program to select from the first axis (K) by the indices tidx to get an array of shape (J=4, I=8) back.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

Set comprehension:

>>> m = {x ** 2 for x in range(5)}
>>> m
{0, 1, 4, 9, 16}