I have a code that goes as:-
.....
path = 'path_to_csv_file';
file=open(path, "r")
reader = csv.reader(file)
y=np.empty((7000,1))
j=0
for line in reader:
y[j]=line[0]
j+=1
....
targets=np.zeros([7000,1,10])
Now, in the first array of targets, I want the y[0]th index to store 1 (y[0] stores integers from 0-9). For that, I wrote:-
targets[0,0,y[0]]=1
But I get an error:-
IndexError: arrays used as indices must be of integer (or boolean) type
When I print y[0], I get:-
[6.]
as the output. What I think is that it's not an integer, so that's probably the source of my error, but I don't know how to fix it. Any help will be appreciated. Thanks!
print(y[0])and show us results. In general there's nothing wrong intargets=np.zeros([7000,1,10])andtargets[0,0,y[0]]=1. Just hardcode y[0] to try (for exampley=[[1,2,3,4,5],[1,2,3,4,5]]). The most likely the error is in readingyfrom file.print(y[0]). It gives me[6.]6,0,0,0....... The answer below works by the way, thanks!