A = 2
B = 3
C = A + B
print C
There are a lot of free Libraries available via the python installer "pip". Let`s take a look at the two most important libraries for science.
import numpy as np
from matplotlib import pylab as plt
Let's look at some arrays. Numpy arrays can be very handy because we can get around using loops or lambda operations. First, we will demonstrate some simple math.
a = np.array([1,2,6,3,2])
b = a**2
print a
print b
c = np.array([[1,2,3],[4,5,6]])
c
d = np.zeros((5,5))
d
d[0,0] = 1
d
d[2,2] = 1
d
plt.imshow(d)
plt.colorbar()
plt.show()
An RGB array consists of three dimensions ($N \times M \times C$)
We create an array with 20x20 pixel in three colors RGB -> (20,20,3) array.
ColorArray = np.ones((20,20,3)).astype(int)
ColorArray[15,:] = 255
ColorArray[:,10] = 150
plt.imshow(ColorArray)
plt.show()
ColorArray = np.ones((20,20,3)).astype(int)
ColorArray[::2 , ::2,1] = 100
ColorArray[1::4,1::4,0] = 200
plt.imshow(ColorArray)
plt.show()
(in an ideal world, without quantum mechanics) -> 2D Minecraft world
CCDnoise = np.random.rand(20,20)*255*0.1
CCDimage = np.zeros((20,20))
CCDimage[10,10] = 200
CCD = CCDnoise + CCDimage
plt.imshow(CCD)
plt.colorbar()
plt.show()
We will continue from here next week.
BayerArray = np.zeros((10,10,3)).astype(int)
BayerArray[1::2,1::2,0] = 255 ### Red
BayerArray[0::2,1::2,1] = 255 ### Green
BayerArray[1::2,0::2,1] = 255 ### Green
BayerArray[0::2,0::2,2] = 255 ### Blue
plt.imshow(BayerArray)
plt.show()