Lecture 06

In [23]:
l1=[6,3,4,7,8,8,1,5,6,2]
ll1=len(l1)
l2=[]
for i in range(ll1):
    j=0
    popindex=0
    minl=l1[0]
    for j in range(0,len(l1)):
        if l1[j]<minl or l1[j]==minl:
            minl=l1[j]
            popindex=j
    l1.pop(popindex)
    l2.append(minl)   
In [24]:
l2
Out[24]:
[1, 2, 3, 4, 5, 6, 6, 7, 8, 8]
In [15]:
l1=[6,3,4,7,8,8,5,6]
minl=l1[0]

    
    
print(minl)
3
  • Matrix Multiplication:
In [25]:
def matrixForm_chek(a):
    x=True
    for i in range(len(a)-1):
        if len(a[i])!=len(a[i+1]):
            x=False
    return x

def twoMatrix_check(a,b):
    if len(a[0])==len(b):
        return True
    else:
        return False

def check_matrix(a,b):
    if matrixForm_chek(a)==True:
        if matrixForm_chek(b)==True:
            if twoMatrix_check(a,b)==True:
                return True
            else:
                print("Error! two matrices are not . prodoctable.")
                return False
        else:
            print("Error! Second array is not in the Matrix form")
            return False
    else:
        print("Error! First array is not in the Matrix form")
        return False

def zeroMatrix(n,m):
    return [[0. for i in range(m)] for j in range(n)]

def aDb(a,b):
    if check_matrix(a,b)==True:
        n=len(a)
        m=len(b[0])
        c=zeroMatrix(n,m)
        for i in range(len(c)):
            for j in range(len(c[0])):
                x=0
                for k in range(len(c[0])):
                    x=x+a[i][k]*b[k][j]
                c[i][j]=x
        return c
In [26]:
a=[[1,2,3],[2,3,1],[8,12,3]]
b=[[1,3,4],[6,1,5],[5,3,1]]
print(aDb(a,b))
[[28, 14, 17], [25, 12, 24], [95, 45, 95]]
  • Import Modules:
In [29]:
import numpy as np
In [31]:
list0=[1,6,8,5,4,8]
In [32]:
list0.append(9)
In [33]:
list0np=np.array(list0)
In [34]:
type(list0)
Out[34]:
list
In [35]:
type(list0np)
Out[35]:
numpy.ndarray
In [36]:
np.max(list0np)
Out[36]:
9
In [37]:
np.mean(list0np)
Out[37]:
5.857142857142857
In [38]:
np.var(list0np)
Out[38]:
6.6938775510204085