I am trying to fix the Python indexError triggered in Goggle Collab, and have tried to read other solutions previously shared, but cannot find the right solution.
IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed
import math
math.log(2)
pred = []
# TODO -- implement this for loop to make predictions
for d in data_ts_prep:
max_p = -float('inf')
max_c = -1
for c_i in range(c):
p = math.log(prior_prob[c_i])
for t in d:
if t in tok2idx:
p += math.log(cond_prob[tok2idx[t], c_i])
if p > max_p:
max_p = p
max_c = c_i
pred.append(max_c)
import numpy as np
V=3
cond_prob = np.zeros(10, float)
cond_prob = cond_prob + 1
cond_prob /= (np.sum(cond_prob, axis=0) + V)
cond_prob
pass
I tried to use the reshape function on the array to make it 1-dimensionl and my attempts did not work.