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
from tensorflow.keras import layers, models | |
# define the model | |
model = models.Sequential(name="Keras Test CNN") | |
model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1))) | |
model.add(layers.MaxPooling2D((2, 2))) | |
model.add(layers.Conv2D(64, (3, 3), activation='relu')) | |
model.add(layers.MaxPooling2D((2, 2))) | |
model.add(layers.Conv2D(64, (3, 3), activation='relu')) | |
model.add(layers.Flatten()) |
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
import numpy as np | |
# first define our input values and all values for k | |
t = np.linspace(0, 1, 200) | |
k = np.arange(0, 1000) | |
f = 10 # frequency in Hertz | |
# from the formula, isolate all factors in the sinus term which include k | |
k = 2 * np.pi * (2 * k - 1) * f |
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
import numpy as np | |
# some sample data in shaped cubic (100, 100, 100) | |
img = np.random.sample((100, 100, 100)) | |
# set all values between 0.5 and 0.6 to zero | |
img[(img < 0.6) & (img > 0.5)] = 0 | |
# in a small sub cube (10, 10, 10).. | |
# .. get index arrays of all elements above 0.6 |
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
import numpy as np | |
img = np.arange(6).reshape(2, 3) | |
# looping over all elements like this ... | |
for x in range(img.shape[0]): | |
for y in range(img.shape[1]): | |
print(img[x, y]) | |
# ... is easier and more readable with numpy |
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
a = np.array([[0, 1, 2], | |
[3, 4, 5]]) | |
b = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) | |
# subsetting of the array (start is included, end is excluded) | |
print(a[0:2, 0:2]) | |
#> [[0 1] | |
#> [3 4]] | |
# striding / stepping "every second entry" |
NewerOlder