The main problem with using a true false array to represent black and white is that it can be difficult to tell which elements are true and which are false.
import numpy as np def rgb2gray(rgb): return np.dot(rgb[...,:3], [0.299, 0.587, 0.114])
This code imports the numpy library and defines a function to convert an RGB image to grayscale. The function takes an RGB image as input and returns a grayscale image.
Contents
Arrays
An array is a collection of items that are stored in contiguous memory locations. Arrays can be created using the list() function, and they can be accessed using the index number (starting at 0) or the name of the array.
An example of an array in Python would look like this:
list(1, 2, 3)
Booleans
In Python, a boolean is a data type that can only take one of two possible values: True or False. In other words, a boolean can be thought of as a “yes” or “no” answer.
Booleans are used in many situations in Python, including when checking for conditions in conditional statements and when making decisions about what code to run.