Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
5bf244d
Done till Excercise 9
djgnatzy Aug 31, 2022
38ab789
Merge branch 'main' of github.com:djgnatzy/MakeAIWork into main
djgnatzy Aug 31, 2022
62c3ac3
After sync ... fingers crossed
djgnatzy Aug 31, 2022
d1a4b28
Merge branch 'main' of github.com:djgnatzy/MakeAIWork into main
djgnatzy Aug 31, 2022
39aecc4
Met aanpassingen en nieuw Lists-bestand
djgnatzy Sep 2, 2022
7d1ff62
Update vectoren_optellen.py
djgnatzy Sep 2, 2022
f17fe48
Update vectoren_optellen.py
djgnatzy Sep 2, 2022
719726a
Scripts voor Vectoren optellen, met opgezochte elegantere oplossing
djgnatzy Sep 2, 2022
4053166
Update JupyterLab
djgnatzy Sep 2, 2022
b3425e1
Script vectoren optellen met notities
djgnatzy Sep 2, 2022
95a5631
Functions ingevuld tot Excercise X
djgnatzy Sep 2, 2022
850163a
Merge branch 'main' of github.com:djgnatzy/MakeAIWork
djgnatzy Sep 2, 2022
c6bcb15
Update notities 2e uitwerking
djgnatzy Sep 2, 2022
62f0c1f
Laatste updates Notebook opdrachten WK1
djgnatzy Sep 5, 2022
574f8a9
Functions bestand update WK1
djgnatzy Sep 5, 2022
c226573
Vectoren optellen - Update WK1
djgnatzy Sep 5, 2022
978e486
Lineare algebra - Matrices vermenigvuldigen
djgnatzy Sep 5, 2022
d9da6e8
Tuples opgelost
djgnatzy Sep 6, 2022
43f834f
Les numerieke simulatie (Car Race)
djgnatzy Sep 9, 2022
ac87922
Notebook Sets
djgnatzy Sep 11, 2022
8f3c0a8
Sets uitgewerkt
djgnatzy Sep 11, 2022
6e72c1a
Sets uitgewerkt
djgnatzy Sep 11, 2022
52b1c0b
Merged - Last changes
djgnatzy Sep 13, 2022
ee9e80c
Notebooks update wk3
djgnatzy Sep 15, 2022
1212d33
Matrixvermenigvuldiging in klasse (1e poging)
djgnatzy Sep 20, 2022
80673ad
Notebook/Opdrachten Update
djgnatzy Sep 27, 2022
b666045
Scripts Batch Update
djgnatzy Sep 27, 2022
2d7c542
Simulations Batch Update
djgnatzy Sep 27, 2022
20ad8a6
Class Shape v1
djgnatzy Sep 27, 2022
2e90bf1
Notebooks Solutions WK1
djgnatzy Sep 27, 2022
f3bb922
Autonomous Car Simulation v1
djgnatzy Sep 29, 2022
98b9e7c
venv
djgnatzy Sep 29, 2022
1d3e63f
Numpy Excercise CSV
djgnatzy Sep 29, 2022
3cfaf78
Tensorflow_Sonar_1
djgnatzy Sep 30, 2022
8706b62
Manual Car - Ruud
djgnatzy Oct 4, 2022
46ebda7
Project 1 - Zelfrijdende auto (Sonar rijdt met TF, rest Under Const…
djgnatzy Oct 5, 2022
68e5882
Mass Commit
djgnatzy Oct 5, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ etc/
share/
.DS_Store
env/
simulations/
log.txt
# simulations/
simpylc/
accessories/
env/Scripts
39 changes: 3 additions & 36 deletions install/install_requirements.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,15 @@ case "${os}" in
*) machine="UNKNOWN:${os}"
esac

function install_with_conda {
if (! command -v "conda" &> /dev/null ) then
echo "Install Miniconda first\n" && exit 0
fi

conda install --yes -c conda-forge \
beautifulsoup4 \
py-cpuinfo \
jupyter_core \
jupyterlab \
keras \
Keras-Preprocessing \
lidar \
matplotlib-base \
numexpr \
pandas \
Pillow \
pyopengl \
pytables \
scikit-image \
scikit-learn \
scipy \
seaborn \
selenium \
statsmodels \
sympy \
tensorflow \
tensorboard-plugin-wit \
tensorflow-estimator \
widgetsnbextension
}

# Install all required libraries t
function install_with_pip {
# Upgrade pip
python3 -m pip install --upgrade pip
python -m pip install --upgrade pip

# Install setuptools
python3 -m pip install setuptools
python3 -m pip install --no-cache-dir -r install/pip/requirements.txt
python -m pip install setuptools
python -m pip install --no-cache-dir -r install/pip/requirements.txt

}

install_with_conda
install_with_pip
13 changes: 12 additions & 1 deletion install/pip/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
jupyterlab
matplotlib
matplotlib-venn
numpy
Pillow
ptpython
scipy
SimPyLC==3.10.0
sonar
sonar
numexpr
pandas
keras
Keras-Preprocessing
scikit-image
scikit-learn
ptpython

1 change: 1 addition & 0 deletions log.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
error during connect: This error may indicate that the docker daemon is not running.: Get "http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/containers/python-ai-jupyter/json": open //./pipe/docker_engine: The system cannot find the file specified.
4 changes: 4 additions & 0 deletions manual_car/1. run-car-sim.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

export LIBGL_ALLOW_SOFTWARE=1
python3 simpylc/simulations/car_manual_flex_track/world.py
4 changes: 4 additions & 0 deletions manual_car/2. run-manual-client.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

cd simpylc/simulations/car_manual_flex_track/control_client/
python3 manual_client.py
10 changes: 10 additions & 0 deletions norm_sonar_01_model/keras_metadata.pb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

�/root"_tf_keras_sequential*�.{"name": "sequential", "trainable": true, "expects_training_arg": true, "dtype": "float32", "batch_input_shape": null, "must_restore_from_config": false, "preserve_input_structure_in_config": false, "autocast": false, "class_name": "Sequential", "config": {"name": "sequential", "layers": [{"class_name": "InputLayer", "config": {"batch_input_shape": {"class_name": "__tuple__", "items": [null, null]}, "dtype": "float32", "sparse": false, "ragged": false, "name": "normalization_input"}}, {"class_name": "Normalization", "config": {"name": "normalization", "trainable": true, "batch_input_shape": {"class_name": "__tuple__", "items": [null, null]}, "dtype": "float32", "axis": {"class_name": "__tuple__", "items": [-1]}, "mean": null, "variance": null}}, {"class_name": "InputLayer", "config": {"batch_input_shape": {"class_name": "__tuple__", "items": [null, 3]}, "dtype": "float32", "sparse": false, "ragged": false, "name": "input_1"}}, {"class_name": "Dense", "config": {"name": "dense", "trainable": true, "dtype": "float32", "units": 16, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name": "Dense", "config": {"name": "dense_1", "trainable": true, "dtype": "float32", "units": 16, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name": "Dense", "config": {"name": "dense_2", "trainable": true, "dtype": "float32", "units": 1, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}]}, "shared_object_id": 12, "input_spec": [{"class_name": "InputSpec", "config": {"dtype": null, "shape": {"class_name": "__tuple__", "items": [null, null]}, "ndim": 2, "max_ndim": null, "min_ndim": null, "axes": {}}}], "build_input_shape": {"class_name": "TensorShape", "items": [null, null]}, "is_graph_network": true, "full_save_spec": {"class_name": "__tuple__", "items": [[{"class_name": "TypeSpec", "type_spec": "tf.TensorSpec", "serialized": [{"class_name": "TensorShape", "items": [null, null]}, "float32", "normalization_input"]}], {}]}, "save_spec": {"class_name": "TypeSpec", "type_spec": "tf.TensorSpec", "serialized": [{"class_name": "TensorShape", "items": [null, null]}, "float32", "normalization_input"]}, "keras_version": "2.10.0", "backend": "tensorflow", "model_config": {"class_name": "Sequential", "config": {"name": "sequential", "layers": [{"class_name": "InputLayer", "config": {"batch_input_shape": {"class_name": "__tuple__", "items": [null, null]}, "dtype": "float32", "sparse": false, "ragged": false, "name": "normalization_input"}, "shared_object_id": 0}, {"class_name": "Normalization", "config": {"name": "normalization", "trainable": true, "batch_input_shape": {"class_name": "__tuple__", "items": [null, null]}, "dtype": "float32", "axis": {"class_name": "__tuple__", "items": [-1]}, "mean": null, "variance": null}, "shared_object_id": 1}, {"class_name": "InputLayer", "config": {"batch_input_shape": {"class_name": "__tuple__", "items": [null, 3]}, "dtype": "float32", "sparse": false, "ragged": false, "name": "input_1"}, "shared_object_id": 2}, {"class_name": "Dense", "config": {"name": "dense", "trainable": true, "dtype": "float32", "units": 16, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 3}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 4}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 5}, {"class_name": "Dense", "config": {"name": "dense_1", "trainable": true, "dtype": "float32", "units": 16, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 6}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 7}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 8}, {"class_name": "Dense", "config": {"name": "dense_2", "trainable": true, "dtype": "float32", "units": 1, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 9}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 10}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 11}]}}, "training_config": {"loss": {"class_name": "MeanSquaredError", "config": {"reduction": "auto", "name": "mean_squared_error"}, "shared_object_id": 14}, "metrics": [[{"class_name": "MeanMetricWrapper", "config": {"name": "accuracy", "dtype": "float32", "fn": "binary_accuracy"}, "shared_object_id": 15}, {"class_name": "MeanMetricWrapper", "config": {"name": "mae", "dtype": "float32", "fn": "mean_absolute_error"}, "shared_object_id": 16}]], "weighted_metrics": null, "loss_weights": null, "optimizer_config": {"class_name": "Adam", "config": {"name": "Adam", "learning_rate": 0.009999999776482582, "decay": 0.0, "beta_1": 0.8999999761581421, "beta_2": 0.9990000128746033, "epsilon": 1e-07, "amsgrad": false}}}}2
�root.layer_with_weights-0"_tf_keras_layer*�{"name": "normalization", "trainable": true, "expects_training_arg": false, "dtype": "float32", "batch_input_shape": {"class_name": "__tuple__", "items": [null, null]}, "stateful": false, "must_restore_from_config": true, "preserve_input_structure_in_config": false, "autocast": true, "class_name": "Normalization", "config": {"name": "normalization", "trainable": true, "batch_input_shape": {"class_name": "__tuple__", "items": [null, null]}, "dtype": "float32", "axis": {"class_name": "__tuple__", "items": [-1]}, "mean": null, "variance": null}, "shared_object_id": 1, "build_input_shape": {"class_name": "TensorShape", "items": [null, 3]}}2
� root.layer-1"_tf_keras_input_layer*�{"class_name": "InputLayer", "name": "input_1", "dtype": "float32", "sparse": false, "ragged": false, "batch_input_shape": {"class_name": "__tuple__", "items": [null, 3]}, "config": {"batch_input_shape": {"class_name": "__tuple__", "items": [null, 3]}, "dtype": "float32", "sparse": false, "ragged": false, "name": "input_1"}}2
�root.layer_with_weights-1"_tf_keras_layer*�{"name": "dense", "trainable": true, "expects_training_arg": false, "dtype": "float32", "batch_input_shape": null, "stateful": false, "must_restore_from_config": false, "preserve_input_structure_in_config": false, "autocast": true, "class_name": "Dense", "config": {"name": "dense", "trainable": true, "dtype": "float32", "units": 16, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 3}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 4}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 5, "input_spec": {"class_name": "InputSpec", "config": {"dtype": null, "shape": null, "ndim": null, "max_ndim": null, "min_ndim": 2, "axes": {"-1": 3}}, "shared_object_id": 17}, "build_input_shape": {"class_name": "TensorShape", "items": [null, 3]}}2
�root.layer_with_weights-2"_tf_keras_layer*�{"name": "dense_1", "trainable": true, "expects_training_arg": false, "dtype": "float32", "batch_input_shape": null, "stateful": false, "must_restore_from_config": false, "preserve_input_structure_in_config": false, "autocast": true, "class_name": "Dense", "config": {"name": "dense_1", "trainable": true, "dtype": "float32", "units": 16, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 6}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 7}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 8, "input_spec": {"class_name": "InputSpec", "config": {"dtype": null, "shape": null, "ndim": null, "max_ndim": null, "min_ndim": 2, "axes": {"-1": 16}}, "shared_object_id": 18}, "build_input_shape": {"class_name": "TensorShape", "items": [null, 16]}}2
�root.layer_with_weights-3"_tf_keras_layer*�{"name": "dense_2", "trainable": true, "expects_training_arg": false, "dtype": "float32", "batch_input_shape": null, "stateful": false, "must_restore_from_config": false, "preserve_input_structure_in_config": false, "autocast": true, "class_name": "Dense", "config": {"name": "dense_2", "trainable": true, "dtype": "float32", "units": 1, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 9}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 10}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 11, "input_spec": {"class_name": "InputSpec", "config": {"dtype": null, "shape": null, "ndim": null, "max_ndim": null, "min_ndim": 2, "axes": {"-1": 16}}, "shared_object_id": 19}, "build_input_shape": {"class_name": "TensorShape", "items": [null, 16]}}2
�[root.keras_api.metrics.0"_tf_keras_metric*�{"class_name": "Mean", "name": "loss", "dtype": "float32", "config": {"name": "loss", "dtype": "float32"}, "shared_object_id": 20}2
�\root.keras_api.metrics.1"_tf_keras_metric*�{"class_name": "MeanMetricWrapper", "name": "accuracy", "dtype": "float32", "config": {"name": "accuracy", "dtype": "float32", "fn": "binary_accuracy"}, "shared_object_id": 15}2
�]root.keras_api.metrics.2"_tf_keras_metric*�{"class_name": "MeanMetricWrapper", "name": "mae", "dtype": "float32", "config": {"name": "mae", "dtype": "float32", "fn": "mean_absolute_error"}, "shared_object_id": 16}2
Binary file added norm_sonar_01_model/saved_model.pb
Binary file not shown.
Binary file not shown.
Binary file added norm_sonar_01_model/variables/variables.index
Binary file not shown.
2 changes: 2 additions & 0 deletions notebooks/csv/marslander.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
length,width,weight,deckHeight,robotArmLength,numberOfSolarPanels,scienceInstruments,image
6,1.56,360,"(83, 108)",1.8,2,"('seismometer', 'heat probe', 'radio science experiment')",../pics/mars.nasa.jpg
63 changes: 63 additions & 0 deletions notebooks/opdrachten/challenge/matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env python

# CHALLENGE:
# Fix nethod multiply
# Implement size_of

class Matrix:

def __init__(self, vectorList):
self.vectorList = vectorList

def __add__(self, matrix2):
vectorList2 = matrix2.vectorList
vectorList3 = [self.addVectors(v1, v2) for (v1, v2) in zip(vectorList1, vectorList2)]
return Matrix(vectorList3)

def addVectors(self, v1, v2):
if len(v1) != len(v2):
return None
else:
v3 = [sum(tup) for tup in zip(v1, v2)]
return v3

# Challenge: Needs to be corrected and finished
def multiply(self, matrix2):
vectorList2 = matrix2.vectorList
vectorColumn2 = list()

for i in range(0, len(vectorList2)):
vectorColumn2.append(vectorList2[i])

print(vectorColumn2)

# columns of matrix2

vectorList3 = [self.multiplyVectors(v1, v2) for (v1, v2) in zip(vectorList1, vectorColumn2)]
return Matrix(vectorList3)

def multiplyVectors(self, v1, v2):
if len(v1) != len(v2):
return None
else:
v3 = [a*b for (a, b) in zip(v1, v2)]
return v3

# Challenge: Overwrite this dunder method
# This method should return a tuple containing the Matrix dimensions
def __sizeof__(self):
pass

def __str__(self):
return f"{self.vectorList}"

vectorList1 = ([1, 1, 1], [1, 1, 1])
vectorList2 = ([1, 2, 3], [4, 5, 6])

matrix1 = Matrix(vectorList1)
matrix2 = Matrix(vectorList2)
matrix3 = matrix1 + matrix2
matrix4 = matrix1.multiply(matrix2)

print(matrix4)
# print(f"Matrix1 {matrix1} + Matrix2 {matrix2} = Matrix3 {matrix3}")
Binary file added notebooks/opdrachten/cheatsheets/Numpy.pdf
Binary file not shown.
Binary file added notebooks/opdrachten/cheatsheets/Pandas.pdf
Binary file not shown.
Binary file not shown.
Binary file added notebooks/opdrachten/diagrams/git-model.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
47 changes: 47 additions & 0 deletions notebooks/opdrachten/examples/employee/employee.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Encapsulation / Information hiding
class Salary:
def __init__(self, pay):
self.pay = pay

def get_total(self):
return (self.pay * 12)

class Employee:
# Constructor method with Arguments
# def __init__(self, firstName, lastName, pay, bonus):
def __init__(self, **kwargs):
self.firstname = kwargs['firstName']
self.lastname = kwargs['lastName']
self.pay = kwargs['pay']
self.bonus = kwargs['bonus']
# Composition
self.obj_salary = Salary(self.pay)

def getFullname(self):
return '{} {}'.format(self.firstname, self.lastname)

@property
def fullname(self):
return '{} {}'.format(self.firstname, self.lastname)

# Docstring
"""
This function calculates and
returns the annual salary
"""
@property
def annualSalary(self):
return self.obj_salary.get_total() + self.bonus

def main():
# Object
employee1 = Employee(firstName="Marc", lastName="Rotsaert", pay=6000, bonus=500)
employee2 = Employee(firstName="Anton", lastName="Diepenhorst", pay=4500, bonus=1000)
print(f"Annual salary of {employee1.getFullname()} : {employee1.annualSalary}")
print(f"Annual salary of {employee2.getFullname()} : {employee2.annualSalary}")
print(f"__name__: {__name__}")

if __name__ == "main":
main()

Employee.main()
69 changes: 69 additions & 0 deletions notebooks/opdrachten/examples/employee/matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env python

class Matrix:

def __init__(self, vectorList):
self.vectorList = vectorList

def __add__(self, matrix2):
vectorList2 = matrix2.vectorList
vectorList3 = [self.addVectors(v1, v2) for (v1, v2) in zip(vectorList1, vectorList2)]
return Matrix(vectorList3)

def addVectors(self, v1, v2):
if len(v1) != len(v2):
return None
else:
v3 = [sum(tup) for tup in zip(v1, v2)]
return v3

def multiply(self, matrix2):
vectorList2 = matrix2.vectorList
vectorColumn2 = list()

for i in range(0, len(vectorList2)):
vectorColumn2.append(vectorList2[i])

print(vectorColumn2)

# columns of matrix2

vectorList3 = [self.multiplyVectors(v1, v2) for (v1, v2) in zip(vectorList1, vectorColumn2)]
return Matrix(vectorList3)

def multiplyVectors(self, v1, v2):
if len(v1) != len(v2):
return None
else:
v3 = [a*b for (a, b) in zip(v1, v2)]
return v3

def __str__(self):
return f"{self.vectorList}"

# vectorList1 = ([1, 1, 1], [1, 1, 1])
# vectorList2 = ([1, 2, 3], [4, 5, 6])



# print(matrix4)
# print(f"Matrix1 {matrix1} + Matrix2 {matrix2} = Matrix3 {matrix3}")

def main():
# Object
vectorList1 = Matrix([1, 1, 1], [1, 1, 1])
vectorList2 = Matrix([1, 2, 3], [4, 5, 6])

print(matrix4)
print(f"Matrix1 {matrix1} + Matrix2 {matrix2} = Matrix3 {matrix3}")
print(f"__name__: {__name__}")

if __name__ == "main":
main()

matrix1 = Matrix(vectorList1)
matrix2 = Matrix(vectorList2)
matrix3 = matrix1 + matrix2
matrix4 = matrix1.multiply(matrix2)

Matrix.main()
53 changes: 53 additions & 0 deletions notebooks/opdrachten/examples/employee/matrix_jeroen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python

class Matrix:

def __init__(self, vectorList):
self.vectorList = vectorList

def __add__(self, matrix2):
vectorList2 = matrix2.vectorList
vectorList3 = [self.addVectors(v1, v2) for (v1, v2) in zip(vectorList1, vectorList2)]
return Matrix(vectorList3)

def addVectors(self, v1, v2):
if len(v1) != len(v2):
return None
else:
v3 = [sum(tup) for tup in zip(v1, v2)]
return v3

def multiply(self, matrix2):
vectorList2 = matrix2.vectorList
vectorColumn2 = list()

for i in range(0, len(vectorList2)):
vectorColumn2.append(vectorList2[i])

print(vectorColumn2)

# columns of matrix2

vectorList3 = [self.multiplyVectors(v1, v2) for (v1, v2) in zip(vectorList1, vectorColumn2)]
return Matrix(vectorList3)

def multiplyVectors(self, v1, v2):
if len(v1) != len(v2):
return None
else:
v3 = [a*b for (a, b) in zip(v1, v2)]
return v3

def __str__(self):
return f"{self.vectorList}"

vectorList1 = ([1, 1, 1], [1, 1, 1])
vectorList2 = ([1, 2, 3], [4, 5, 6])

matrix1 = Matrix(vectorList1)
matrix2 = Matrix(vectorList2)
matrix3 = matrix1 + matrix2
matrix4 = matrix1.multiply(matrix2)

print(matrix4)
print(f"Matrix1 {matrix1} + Matrix2 {matrix2} = Matrix3 {matrix3}")
Loading