Skip to content

Commit

Permalink
Week 09
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmetanildindar committed Apr 28, 2021
1 parent 692fde7 commit 87e5640
Show file tree
Hide file tree
Showing 3 changed files with 1,036 additions and 4 deletions.
59 changes: 59 additions & 0 deletions .ipynb_checkpoints/CE302-Week08-checkpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
##############################################
# 2021_0414-AAD: Multhithreading Example #
##############################################
# There are two approaches in code efficiency:
# 1. Parallel process : splitting the cpus
# 2. Creating paralle threads
###############################

#%% IMPORTS

import os, pandas as pd , time , datetime, numpy as np

import threading # module for multithreading

#%%
exitFlag = 0

class MyThread( threading.Thread) :
def __init__( self , threatID , name , my_delay) :
threading.Thread.__init__(self)
self.threatID = threatID
self.name = name
self.delay = my_delay

def run(self):
print( f"Starting : {self.name}" )

print_time( self.name , self.delay , 5 )

print( f"Exiting : {self.name}")

def print_time( threadName , my_delay , counter ):

while counter :
if exitFlag :
threadName.exit()
time.sleep( my_delay )

print( f"{threadName} : time is {time.ctime(time.time())}")

counter -= 1

#%%
# Crate the threats

thread_1 = MyThread( 1 , "Thread name 1" , 1)

thread_2 = MyThread( 2 , "Thread name 2" , 5)

# Start the threads

#%%

thread_1.start()
thread_2.start()

print( f"The file is ok")

# %%
289 changes: 289 additions & 0 deletions .ipynb_checkpoints/CE302-Week09-checkpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,295 @@
"source": [
"# CE302 ADVANCED PROGRAMMING TECHNIQUES FOR ENGINEERS"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create the vectors"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"vect = np.array([1,2,3])"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 2, 3])"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"vect.T"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(3,)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"vect.T.shape"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create a matrix from the vectors"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"vec1 = np.array([1,2,3])\n",
"vec2 = np.array([3,4,5])\n",
"vec3 = np.array([4,5,6])"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Variable Type Data/Info\n",
"-------------------------------\n",
"np module <module 'numpy' from '/Us<...>kages/numpy/__init__.py'>\n",
"os module <module 'os' from '/Users<...>da3/lib/python3.8/os.py'>\n",
"sys module <module 'sys' (built-in)>\n",
"vec1 ndarray 3: 3 elems, type `int64`, 24 bytes\n",
"vec2 ndarray 3: 3 elems, type `int64`, 24 bytes\n",
"vec3 ndarray 3: 3 elems, type `int64`, 24 bytes\n",
"vect ndarray 3: 3 elems, type `int64`, 24 bytes\n"
]
}
],
"source": [
"whos"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"myMatrice = np.vstack([vec1 , vec2 , vec3])"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[1, 2, 3],\n",
" [3, 4, 5],\n",
" [4, 5, 6]])"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"myMatrice"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 4, 6])"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"myMatrice.diagonal()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[1, 3, 4],\n",
" [2, 4, 5],\n",
" [3, 5, 6]])"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"myMatrice.T"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(3, 3)"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"myMatrice.shape"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Summation"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 2, 4, 6],\n",
" [ 6, 8, 10],\n",
" [ 8, 10, 12]])"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"myMatrice + myMatrice"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 2, 4, 6],\n",
" [ 6, 8, 10],\n",
" [ 8, 10, 12]])"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.add( myMatrice , myMatrice)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Subtraction"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0, 0, 0],\n",
" [0, 0, 0],\n",
" [0, 0, 0]])"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"myMatrice - myMatrice\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading

0 comments on commit 87e5640

Please sign in to comment.