```
IndexError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_22004\4114403535.py in <module>
----> 1 baum_welch(v, A, B, PI, n_iter=100)
~\AppData\Local\Temp\ipykernel_22004\1962654577.py in baum_welch(V, a, b, initial_distribution, n_iter)
4
5 for n in range(n_iter):
----> 6 alpha = forward(V, a, b, initial_distribution)
7 beta = backward(V, a, b)
8
~\AppData\Local\Temp\ipykernel_22004\4009087898.py in forward(V, a, b, initial_distribution)
1 def forward(V, a, b, initial_distribution):
2 alpha = np.zeros((V.shape[0], a.shape[0]))
----> 3 alpha[0, :] = initial_distribution * b[:, V[0]]
4
5 for t in range(1, V.shape[0]):
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
```

```
import numpy as np
def forward(V, a, b, initial_distribution):
alpha = np.zeros((V.shape[0], a.shape[0]))
alpha[0, :] = initial_distribution * b[:, V[0]]
for t in range(1, V.shape[0]):
for j in range(a.shape[0]):
# Matrix Computation Steps
# ((1x2) . (1x2)) * (1)
# (1) * (1)
alpha[t, j] = alpha[t - 1].dot(a[:, j]) * b[j, V[t]]
return alpha
```

Comments:

2023-01-21 00:30:12

Welcome to Stack Overflow! Please take a look at How to Ask and minimal reproducible example. Can provide some context for what you're trying to do, along with fully reproducible code that produces this error, and your expected output?

2023-01-21 00:30:12

you must have called this function for the error to have been caused. so how did you run it and with what arguments ?

Answers(0) :