*I will be importing the neural net base code for this neural network.*

```
In [1]:
```import NeuralNetImport as NN
import numpy as np
import NNpix as npx
from IPython.display import Image

```
In [2]:
```npx.morse1

```
Out[2]:
```

```
In [39]:
```enter = input("Enter Your Morse: ")

```
```

Use two functions to turn a morse code sentence into a 3D array of numbers. This first function turns the morse code into string numbers. Each dot is "0.5" and each dash is "1.0". Each letter is an array, each word is an array of arrays, and each sentence is an array of arrays of arrays.

```
In [40]:
```def morse_to_num_str(morse):
""" Takes morse code and divides in into a 3D array, 1D for each letter, 2D for each word, and 3D for the sentence"""
morse = morse.replace(".", "0.5,")
morse = morse.replace("-", "1.0,")
new = list(morse)
for i in range(len(new)):
if i > 1 and new[i-1] == "," and new[i] == " ":
new[i-1] = " "
if i == (len(new)-1):
new[i] = ""
new = "".join(new)
a = new.split(" ")
for i in range(len(a)):
a[i] = a[i].split(" ")
for h in range(len(a)):
for j in range(len(a[h])):
a[h][j] = a[h][j].split(",")
return a

```
In [41]:
```assert morse_to_num_str("-. -- -- ..") == [[['1.0', '0.5'], ['1.0', '1.0']], [['1.0', '1.0'], ['0.5', '0.5']]]

```
In [42]:
```def morse_str_to_float(morse):
""" Turns the 3D array generated above into float"""
""" Adds 0.0 for letters without 4 elements"""
for i in range(len(morse)):
for j in range(len(morse[i])):
while len(morse[i][j]) != 4:
morse[i][j].append("0.0")
for k in range(len(morse[i][j])):
morse[i][j][k] = float(morse[i][j][k])
return np.array(morse)

```
In [43]:
```assert np.all(morse_str_to_float([[['1.0', '0.5'], ['1.0', '1.0']], [['1.0', '1.0'], ['0.5', '0.5']]]) == np.array(([[[ 1. , 0.5, 0. , 0. ],
[ 1. , 1. , 0. , 0. ]],[[ 1. , 1. , 0. , 0. ],[ 0.5, 0.5, 0. , 0. ]]])))

```
In [44]:
```""" The entire morse alphabet in numerical morse"""
all_in = np.genfromtxt("MorseTxt.txt", delimiter=",", usecols=(1,2,3,4))

```
In [45]:
```""" The letters that correspond with all-in above"""
real_letters = np.genfromtxt("MorseTxt.txt", dtype=str, delimiter=",", usecols=(0))
""" 26 element array of all the ouputs"""
all_out = NN.create_training_soln(np.genfromtxt("MorseTxt.txt", dtype=str, delimiter=",", usecols=(0)),26)

```
In [46]:
```morse_net = NN.NN_training(all_in, all_out, 4, 26, 30, 400, 0.7)

```
In [47]:
``````
# x,y = morse_net.train()
```

```
In [48]:
```f = np.load("MorseWeights.npz")

```
In [49]:
```x = f['arr_0']
y = f['arr_1']

```
In [50]:
```assert len(x) == 30
assert len(y) == 26

```
In [51]:
```morse_ask = NN.NN_ask(all_in, x, y)

```
In [52]:
```comp_vals = [chr(morse_ask.get_ans()[i]+65) for i in range(26)]

```
In [53]:
```assert np.all(comp_vals == real_letters)

```
In [54]:
```new_net = NN.NN_ask_morse(morse_str_to_float(morse_to_num_str(enter)), x, y)

```
```

```
In [55]:
```ans = new_net.get_ans()

```
In [56]:
```print("".join([chr(ans[i]) for i in range(len(ans))]))

```
```

```
In [ ]:
```

```
In [ ]:
```