1 3
1 3
list1 = [1,5,6,2]
#List of Lists
list2 = [ [1,5,6,2], [3,2,1,3] ]
#Non-homologous List
#It may not be considered as an Array
list4 = [ [4,2,3], [5,1] ]
>>> X = [4, 5] #LIST
>>> print(type(X))
<class 'list'>
>>> Y = {4: 'four', 5: 'five'} #Dictionary
>>> print(type(Y))
<class 'dict'>
for i in range(len(X)):
... Z.append(X[i]+10)
print(X,Z)
import matplotlib.pyplot as plt
Z=[ ]
X=[0,1,2,4,5,6]
Y=[1,4,8,16,25,49]
fig,ax=plt.subplots( )
ax.plot(X,Y)
plt.show( )
for i in range(len(X)):
... Z.append(X[i]+10)
print(X,Z)
fig,ax=plt.subplots()
ax.plot(X,Z,"ob")
>>> X= zip(numericalList, stringList)
>>> XList = list(X)
>>> print(XList)
[(4, 'four'), (5, 'five'), (6, 'six')]
>>>
#3-dimenasional array
matrix2 = [ [ [1,5,6,2], [3,2,1,3] ], [ [5,2,1,2], [6,4,8,4] ], [ [2,8,5,3], [1,1,9,4] ] ]
# Shape is 3 x 2 x 4
# A batch of input
batch = [[1,5,6,2], [3,2,1,3],
[5,2,1,2], [6,4,8,4]
[2,8,5,3], [1,1,9,4],
[6,6,0,4], [8,7,6,4]
# shape (8,4) type: 2d array or a matrix
import numpy as np
ar = np.array(0)
print(ar)
print("Shape of the array:")
print(ar.shape)
import numpy as np
ar = np.array([[12,20] ,[13,15]])
print(ar)
print("Shape of the array:")
print(ar.shape)
a = [1,2,3]
b = [2,3,4]
dot_product = a[0]*b[0] + a[1]*b[1] + a[2]*b[2]
print(dot_product)
import numpy as np
inputs = [1.0, 2.0, 3.0, 2.5]
weights = [0.2, 0.8, -0.5, 1.0]
bias = 2.0
outputs = np.dot(weights, inputs) + bias
print(outputs)
import numpy as np
inputs = [1.0, 2.0, 3.0, 2.5]
weights = [[0.2, 0.8, -0.5, 1],
[0.5, -0.91, 0.26, -0.5],
[-0.26, -0.27, 0.17, 0.87]]
biases = [2.0, 3.0, 0.5]
layer_outputs = np.dot(weights, inputs) + biases
print(layer_outputs)
#Another homologous list or an array
#Also called feature set instances
# Also called Observations
a = [1, 2, 3]
np.array([a])
#or
#a = [1, 2, 3]
#np.expand_dims(np.array(a), axis=0)
# A row vector is a matrix whose first dimension’s size (the
number of rows) equals 1 and the second dimension’s size (the
number of columns) equals n i.e. the vector size.
In other words, it’s a 1×n array or array of shape (1, n)
● # A column vector is a matrix where the second dimension’s
size equals 1, in other words, it’s an array of shape (n, 1)
# Now
import numpy as np
a = [1, 2, 3]
b = [2, 3, 4]
#multiple A x B
# i.e. Multiply row element of A with Column value of B to obtain Output value
#So, we transpose B and multiply using Dot Product A x Transpose (B)
a = np.array([a])
b = np.array([b]).T
np.dot(a, b)
● We have achieved the same result as the dot product of two
vectors, but performed on matrices and returning a matrix —
exactly what we expected and wanted.
● It’s worth mentioning that NumPy does not have a dedicated
method for performing matrix product — the dot product and
matrix product are both implemented in a single method: np.dot().
import numpy as np
inputs = [[1.0, 2.0, 3.0, 2.5],
[2.0, 5.0, -1.0, 2.0],
[-1.5, 2.7, 3.3, -0.8]]
weights = [[0.2, 0.8, -0.5, 1.0],
[0.5, -0.91, 0.26, -0.5],
[-0.26, -0.27, 0.17, 0.87]]
biases = [2.0, 3.0, 0.5]
layer_outputs = np.dot(inputs, np.array(weights).T) + biases
print(layer_outputs)
● # A lambda function is a small anonymous function.
● # A lambda function can take any number of arguments, but can only have one expression.
● # Use lambda functions when an anonymous function is required for a short period of time.
● x = lambda a : a + 10
● print(x(5))
● x = lambda a, b : a * b
● print(x(5, 6))
● def myfunc(n):
● return lambda a : a * n
● def myfunc(n):
● return lambda a : a * n
● mydoubler = myfunc(2)
● print(mydoubler(11))
● def myfunc(n):
● return lambda a : a * n
● mydoubler = myfunc(2)
● mytripler = myfunc(3)
● print(mydoubler(11))
● print(mytripler(11))