import numpy as np

a = np.array([1, 2, 3])  
print type(a)            
print a.shape            

print a                  

"""
Explanation: Introduction to arrays in numpy
The "numpy" is the efficient numerical computation library of python. We start with defining arrays and their basic manipulation. Arrays are like lists except their type is fixed for each element. The common types are int and float.
We start with a one dimensional array of size 3.
1. General syntax
End of explanation
"""


b = np.array([[1, 2, 3], [4, 5, 6]])   
print b.shape                     


print b[:, :]

"""
Explanation: Now we define a two-dimensional array of size 2$\times$3
End of explanation
"""


print np.full((2, 3), 7.0)

"""
Explanation: Any time you need help you can write "numpy.array?", you may initialize a matrix using "numpy.full"
End of explanation
"""


print np.zeros((3, 3))


print np.eye(4) #gives identity matrix

"""
Explanation: This initializes a 2$\times$3 with value float 7.0. try other functions like numpy.zeros, numpy.ones, and numpy.eye
End of explanation
"""


import numpy as np
a = np.array([[1, 2], [3, 4], [5, 6]])
print (a>2)

print a[a>2]

myarray=np.eye(10)
print myarray == 1

print myarray[myarray == 1]

print range(1,len(myarray)+1)

"""
Explanation: 2. Boolean array indexing
Using the boolean array indexing you pick up the elements of an array. This type of indexing helps you to select the elements of an array that satisfy a condition. You must be aware that arrays in numpy is different from lists in python. However, we can convert a numeric list to a numpy array using np.array
End of explanation
"""


myarray=np.eye(10)
myarray[myarray == 1] = range(1, len(myarray)+1)
print myarray

"""
Explanation: Exercise<br>
Produce an identity matrix of size 10 and 
replace the diagonal elements with 1 to 10.
End of explanation
"""


type(myarray)

vector = (range(1, len(myarray)+1))
(np.array(vector))**2

"""
Explanation: Replace the non-zero elements of the last matrix with increasing powers of 2.
End of explanation
"""


x = np.array([[1,2],[3,4]], dtype=np.float64)
y = np.array([[5,6],[7,8]], dtype=np.float64)
print x+y
print np.add(x, y)

print x-y
print np.subtract(x, y)

print x*y
print np.multiply(x, y)

print x/y
print np.divide(x, y)

"""
Explanation: 3. Matrix operations
Elementwise operation
Element-wise matrix operations are as follows
Take 
$x=\left(\begin{array}{c c} 1&2\3&4 \end{array}\right) ~~~~$ 
$y=\left(\begin{array}{c c} 5&6\7&8 \end{array}\right)$
End of explanation
"""


print x.dot(y)
print np.dot(x, y)

"""
Explanation: Dot product
Matrix product is the "dot" operator. It can be used with only one, or two arguments
End of explanation
"""


print np.sum(x, axis = 1) # on rows 
print np.sum(x, axis = 0) # on columns
print np.sum(x, axis = None)  # on both

"""
Explanation: Matrix sum
The sum of a matrix can be implemented on rows, on columns, or on the total matrix.
End of explanation
"""


print x.T
print np.sum(x.T, axis = 0) # gives sum over rows (and not columns even with axis=0)

"""
Explanation: Matrix transpose
The function for transposing a matrix is .T
End of explanation
"""


print np.tile(x, (2, 3))

"""
Explanation: Repeating a matrix
Repeating a matrix several times on rows and columns. This is a special case of the kronecker product
End of explanation
"""


print range(10)
print np.reshape(range(10), (2, 5) )

print np.reshape(range(10),(5,2) )

"""
Explanation: Reshaping a matrix
End of explanation
"""


import matplotlib.pylab as plt

%matplotlib inline
img = plt.imread('../data/cat.jpg')

print img.shape
plt.imshow(img)


img_tinted = img * [0.0, 0.0, 1.0] #Red Green Blue 
print img_tinted.shape

plt.imshow(img_tinted)
plt.axis("off")

img_tinted = img * [.27, .72, 0.07]
#img_tinted = img * [0.33, 0.33, 0.33]
print plt.imshow(img_tinted)

print plt.imshow(np.sum(img_tinted, axis = 2))

print plt.imshow(np.sum(img_tinted, axis=2), "gray")
plt.axis("off")

"""
Explanation: Now let's use some image libraries and plot some pictures.
End of explanation
"""


