NumPy - Why Logo has a Cube in it?
Most of us who use NumPy Library of Python may often wonder,
Why the Logo of NumPy Library has a Cube showing in it?
Have you ever thought how come our digital screen is so much colorful? Well in the context of Digital Screen which is a set of Pixels arranged in a Tabular form, a single pixel may take 16,777,216 different colors. This is because each pixel is a combination of 256 Intensity Levels of Red,?Green?and?Blue.
The Color of a Pixel shall be White if the intensity of Red, Green and Blue is at Maximum i.e. 255 and Color of an Image shall be Black if intensity of all three components of RGB Color System is 0, which indicates an absence of Color.
The Pixels that are Red have an RGB Color Code of (255, 0, 0) while pixels that are Green have an RGB Color Code of (0, 255, 0). Similarly, Pixels that are Blue in Color have an RGB Color Code of (0, 0, 255).
I always wondered how a Pixel accommodates the Intensity of 3 Colors and gives the Resultant Color on screen. Well, it turns out that it is basically a 3D Cube with one side exposed to us.
It is quite similar to the NumPy 3-Dimensional Array. Infact we can store the Data of Pixel Colors in a 3-Dimensional NumPy Array.
领英推荐
# Importing NumPy Library
import numpy as np
# Importing Matplotlib Library
import matplotlib.pyplot as plt
# Creating a 3-Dimensional NumPy Array and assigning the Variable 'image' to it
image = np.array([[[255, 0, 0], [0, 255, 0], [0, 0, 255]],
[[0, 255, 0], [0, 0, 255], [255, 0, 0]],
[[0, 0, 255], [255, 0, 0], [0, 255, 0]]])
# Plotting the Image via Data stored in NumPy Array
plt.imshow(image)
The Code above shall display an Image which shall be identical to [image - b].
Similarly, in order to have an Image of Pixel Size 3 x 3, with all Pixels white in Color, each component of the RGB Code of all the pixel needs to at the maximum.
# Importing NumPy Library
import numpy as np
# Importing Matplotlib Library
import matplotlib.pyplot as plt
# Creating a 3-Dimensional NumPy Array and assigning the Variable 'image' to it
image = np.array([[[255, 255, 255], [255, 255, 255], [255, 255, 255]],
[[255, 255, 255], [255, 255, 255], [255, 255, 255]],
[[255, 255, 255], [255, 255, 255], [255, 255, 255]]])
# Plotting the Image via Data stored in NumPy Array
plt.imshow(image)
The Screen shall display Complete White Image as a result of this Code. Let us Visualize the entire background of how NumPy is storing the Data.
This is just one of the Example how NumPy may help us in storing "Data". The Pixel RGB Color Code Intensity is indeed "Data".
If this article was able to help in understanding a new concept or just gave you a reminder of what you already knew. I would humbly request you to share and like it.
My YouTube Channel: Haris Jafri -YT Channel
My LinkedIn Profile: Haris Jafri - LinkedIn Profile
I love to study, write and teach, so if you have an idea, do let me know!
Digital Control Systems || OT || IT || AI || ML || Cyber Security
5 个月ND Array using Numpy is superb.