-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bb0b734
Showing
10 changed files
with
379 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"tests": [ | ||
{ | ||
"name": "Test", | ||
"setup": "sudo -H pip3 install pytest numpy", | ||
"run": "pytest", | ||
"input": "", | ||
"output": "", | ||
"comparison": "included", | ||
"timeout": 10, | ||
"points": null | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name: GitHub Classroom Workflow | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
name: Autograding | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: education/autograding@v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
|
||
.vscode/ | ||
.idea/ | ||
.pytest_cache/ | ||
.directory | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Homework 4 - Basic NumPy | ||
|
||
The deadline of this homework is on **Tuesday, 16th of May, 23:59:00 UTC+2**. | ||
|
||
In this homework you should implement three different functions in their respective files. | ||
|
||
|
||
### 1 Strange Pattern | ||
|
||
You come across this strange pattern. | ||
|
||
| x | | | x | | | x | | | ||
| ----- | ----- | ----- | ----- | ----- | ----- | ----- | ----- | | ||
| | | **x** | | | **x** | | | | ||
| | **x** | | | **x** | | | **x** | | ||
| **x** | | | **x** | | | **x** | | | ||
| | | **x** | | | **x** | | | | ||
| | **x** | | | **x** | | | **x** | | ||
|
||
Mesmerized, you decide you must write a function to generate arbitrary sizes of it. (_Write a function `strange_pattern` that takes a shape tuple `(n, m)` as input and generates a boolean (True for x's and False for blank spaces) 2D NumPy array of the given shape with this pattern_) | ||
|
||
**Hint:** Perhaps this strange symbol might help? `::` | ||
|
||
### 2 Gaussian analysis | ||
|
||
Write a function `gaussian_analysis` which takes four parameters `loc`, `scale`, `lower_bound` and `upper_bound` and returns a tuple of two values (`mean`, `std`). | ||
First of all the function should make sure that `loc`, `scale`, `lower_bound` and `upper_bound` are integers or floats and that `lower_bound` is smaller than `upper_bound` and should return meaningful error messages if those are not the case. | ||
In the function 100 samples of a gaussian distribution should be drawn in respect to the given `loc` and `scale` parameters. Check out the Numpy documentation to find out which function you could use here. | ||
Next, the values below the `lower_bound` and above the `upper_bound` should be filtered out. Afterwards you should calculate the `mean` and the `std`(standard deviation) of the array and return them in a tuple. | ||
|
||
|
||
|
||
### 3. Combination of arrays | ||
|
||
Write a function `combination` that takes in two numpy arrays and an optional parameter `axis` which should be 0 by default. | ||
Remove unnecessary dimensions of the input arrays, check whether they can be combined along the given axis and return the combined array. | ||
If the combination is not possible, raise a meaningful error message. | ||
|
||
Good luck! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import numpy as np | ||
|
||
# implement your function to combine two numpy arrays | ||
|
||
def combination(): | ||
# delete the NotImplementedError when you write your function. | ||
raise NotImplementedError | ||
|
||
|
||
if __name__ == "__main__": | ||
# use this for your own testing! | ||
|
||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import numpy as np | ||
|
||
# implement the function gaussian_analysis | ||
|
||
def gaussian_analysis(): | ||
|
||
# delete the NotImplementedError when you write your function. | ||
raise NotImplementedError | ||
|
||
|
||
if __name__ == "__main__": | ||
# use this for your own testing! | ||
|
||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import numpy as np | ||
|
||
# implement the function strange pattern | ||
|
||
def strange_pattern(): | ||
# delete the NotImplementedError when you write your function. | ||
raise NotImplementedError | ||
|
||
|
||
if __name__ == "__main__": | ||
# use this for your own testing! | ||
|
||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from hashlib import sha1 | ||
import numpy as np | ||
import types | ||
|
||
try: | ||
import combination as testfile | ||
except ModuleNotFoundError: | ||
assert False, "The name of your file is suppoesed to be 'combination.py'!" | ||
|
||
def imports_of_your_file(filename): | ||
""" Yields all imports in the testfile. """ | ||
|
||
for name, val in vars(testfile).items(): | ||
if isinstance(val, types.ModuleType): | ||
# get direct imports | ||
yield val.__name__ | ||
|
||
else: | ||
# get from x import y imports | ||
imprt = getattr(testfile, name) | ||
|
||
if hasattr(imprt, "__module__") and not str(imprt.__module__).startswith("_") and not str(imprt.__module__) == filename: | ||
yield imprt.__module__ | ||
|
||
|
||
def test_imports(filename="combination", allowed_imports={"numpy"}): | ||
""" Checks if any non-allowed imports have been done. """ | ||
|
||
assert set(imports_of_your_file( | ||
filename)) <= allowed_imports, "You are not allowed to import any modules except NumPy!" | ||
|
||
|
||
def test_combination(): | ||
a = np.array([[[[1, 2], [3, 4], [5, 6]]]]) | ||
b = np.ones((2,2)) | ||
|
||
result = testfile.combination(a,b) | ||
|
||
assert sha1(result).hexdigest( | ||
) == '5709b4ea8b49ac48d42ae3e0bd1b3fb0dbb3249b', 'Your function does not return the right result!' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from hashlib import sha1 | ||
|
||
import numpy as np | ||
import types | ||
|
||
try: | ||
import gaussian_analysis as testfile | ||
except ModuleNotFoundError: | ||
assert False, "The name of your file is suppoesed to be 'gaussian_analysis.py'!" | ||
|
||
def imports_of_your_file(filename): | ||
""" Yields all imports in the testfile. """ | ||
|
||
for name, val in vars(testfile).items(): | ||
if isinstance(val, types.ModuleType): | ||
# get direct imports | ||
yield val.__name__ | ||
|
||
else: | ||
# get from x import y imports | ||
imprt = getattr(testfile, name) | ||
|
||
if hasattr(imprt, "__module__") and not str(imprt.__module__).startswith("_") and not str(imprt.__module__) == filename: | ||
yield imprt.__module__ | ||
|
||
|
||
def test_imports(filename="gaussian_analysis", allowed_imports={"numpy"}): | ||
""" Checks if any non-allowed imports have been done. """ | ||
|
||
assert set(imports_of_your_file( | ||
filename)) <= allowed_imports, "You are not allowed to import any modules except NumPy!" | ||
|
||
def test_gaussian_analysis(): | ||
loc = 0 | ||
scale = 3 | ||
lower_bound = 1 | ||
upper_bound = 3 | ||
|
||
result = testfile.gaussian_analysis(loc,scale,lower_bound,upper_bound) | ||
assert type(result) is tuple, 'Your function does not return the right form of result!' | ||
assert result[0] < upper_bound and result[0] > lower_bound, 'Your function does not return the right result!' | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from hashlib import sha1 | ||
|
||
import numpy as np | ||
import types | ||
|
||
try: | ||
import strange_pattern as testfile | ||
except ModuleNotFoundError: | ||
assert False, "The name of your file is suppoesed to be 'strange_pattern.py'!" | ||
|
||
def imports_of_your_file(filename): | ||
""" Yields all imports in the testfile. """ | ||
|
||
for name, val in vars(testfile).items(): | ||
if isinstance(val, types.ModuleType): | ||
# get direct imports | ||
yield val.__name__ | ||
|
||
else: | ||
# get from x import y imports | ||
imprt = getattr(testfile, name) | ||
|
||
if hasattr(imprt, "__module__") and not str(imprt.__module__).startswith("_") and not str(imprt.__module__) == filename: | ||
yield imprt.__module__ | ||
|
||
|
||
def test_imports(filename="strange_pattern", allowed_imports={"numpy"}): | ||
""" Checks if any non-allowed imports have been done. """ | ||
|
||
assert set(imports_of_your_file( | ||
filename)) <= allowed_imports, "You are not allowed to import any modules except NumPy!" | ||
|
||
|
||
def test_strange_pattern(): | ||
result = testfile.strange_pattern((10, 10)) | ||
|
||
assert type( | ||
result) is np.ndarray, "Your function does not return a NumPy array!" | ||
assert result.dtype is np.dtype( | ||
"bool"), "Your function does not return a boolean array!" | ||
assert sha1(result).hexdigest( | ||
) == '7e69ac17197f17ebccf456b6dfbbe95fe938b7d9', "Your function does not produce the correct pattern!" | ||
|
||
result = testfile.strange_pattern((2, 2)) | ||
|
||
assert sha1(result).hexdigest( | ||
) == "3c585604e87f855973731fea83e21fab9392d2fc", "Your function does not produce the correct pattern in an edge case!" | ||
|
||
result = testfile.strange_pattern((0, 0)) | ||
|
||
assert result.shape == ( | ||
0, 0), "Your function does not produce the correct pattern in an edge case!" |