I was doing my coding practice of python using numpy. I wrote this code:
def create_traini_data(): trainingday_data = [1100] for img in tqdm(os.listdir(TRAIN_DIR)): label = label_img(img) path = os.path.join(TRAIN_DIR, img) training_data.append([np.array(img), np.array(label)]) shuffle(trainingday_data) np.save('traini_data.npy', training_data) return training_data traini_data = create_traini_data() traini = traini_data[:-400]
It throws error:
ValueError: setting an array element with a sequence
Can anybody help?
You can solve this in two ways . The first way is:
X = np.array([i[0] for i in traini]).reshape(-1, IMG_SIZE, IMG_SIZE, 1)
And the secoend way is:
MyX=np.asarray( traini[0]) X = MyX.reshape(-1, IMG_SIZE, IMG_SIZE, 1)