[O] Optimize A1 p4

This commit is contained in:
Hykilpikonna
2021-09-19 22:03:32 -04:00
parent ff0e645697
commit 072467132b
2 changed files with 11 additions and 7 deletions
+8
View File
@@ -0,0 +1,8 @@
`PHL240H1` - [3.0L] [Persons, Minds and Bodies](https://artsci.calendar.utoronto.ca/course/PHL240H1)
`PHL245H1` - [3.0L] [Modern Symbolic Logic](https://artsci.calendar.utoronto.ca/course/PHL245H1)
`PHL246H1` - [3.0L] [Probability and Inductive Logic](https://artsci.calendar.utoronto.ca/course/PHL246H1)
`PHL345H1` - [3.0L] [Intermediate Logic](https://artsci.calendar.utoronto.ca/course/PHL345H1)
`PHL347H1` - [3.0L] [Modal Logic and Philosophical Applications of Logic](https://artsci.calendar.utoronto.ca/course/PHL347H1)
`PHL348H1` - [3.0L] [Logic and Computation](https://artsci.calendar.utoronto.ca/course/PHL348H1)
`PHL349H1` - [3.0L] [Set Theory](https://artsci.calendar.utoronto.ca/course/PHL349H1)
`PHL355H1` - [3.0L] [Philosophy of Natural Science](https://artsci.calendar.utoronto.ca/course/PHL355H1)
+3 -7
View File
@@ -64,9 +64,7 @@ def add_pepper(pixel_data: list, k: int) -> list:
Because of the randomness, we can't specify an exact doctest.
"""
# I don't know why I have to use divide_channels here. I can just use (0,0,0)
return [random.choice([pixel] * k + [divide_channels(pixel, 256)]) for pixel in pixel_data]
return [divide_channels(random.choice([1] * k + [256]) for pixel in pixel_data]
def add_salt(pixel_data: list, k: int) -> list:
@@ -86,9 +84,7 @@ def add_salt(pixel_data: list, k: int) -> list:
Because of the randomness, we can't specify an exact doctest.
"""
# I don't know why I have to use maximize_channels here. I can just use (255,255,255)
return [random.choice([pixel] * k + [maximize_channels(pixel, 255)]) for pixel in pixel_data]
return [maximize_channels(random.choice([0] * k + [255]) for pixel in pixel_data]
def add_salt_and_pepper(pixel_data: list, k: int) -> list:
@@ -121,7 +117,7 @@ if __name__ == '__main__':
import doctest
doctest.testmod()
# run_salt_and_pepper_example('images/horses.png', 'images/noisy-horses.png', 16)
run_salt_and_pepper_example('images/horses.png', 'images/noisy-horses.png', 16)
# When you are ready to check your work with python_ta, uncomment the following lines.
# (Delete the "#" and space before each line.)