Reputation: 1281
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!
Upvotes: 1
Views: 40
Reputation: 6547
Have you tried with dtype=int
?
y=np.empty((7000,1), dtype=int)
...
targets=np.zeros(([7000,1,10]), dtype=int)
You can check more on the documentation on the usage of numpty.empty and numpty.zeros
Upvotes: 1