I want to save a value into an array using numpy. All is working fine but when I try to save the values in the array I am getting an error. Here is what I've done so far:
import numpy as np
batchSize = 2
numClasses = 2
maxSeqLength = 10 #Maximum length of sentence
labels = []
arr = np.zeros([batchSize, maxSeqLength])
for i in range(batchSize):
num = randint(1,17)
labels.append([1,0])
# print(num)
print(labels)
print(ids[num-1:num])
arr[i]=ids[num-1:num]
When I print ids matrix I am getting these values
[[1, 0]]
[[ nan 11501. 420. 5842. nan 4245. nan 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]
[[1, 0], [1, 0]]
[[ nan nan 7624. 3936. 11501. 8064. 5842. nan nan 1087.
37. 11516. nan 10936. nan 12111. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]
and this is the error I am getting when saving the arr array
could not broadcast input array from shape (30) into shape (10)
numClassesbut don't ever use it. You usemaxSeqLengthbut it is never defined.arr[i]has maxSeqLength whileids[num-1:num]has a different length.