Click here to Skip to main content
14,237,525 members
Rate this:
Please Sign up or sign in to vote.
See more:
There is train variable of list type, which conatains two elements - array of img type variables and the array of labels. I need to write the first array(of imgs) to X and then process it with reshape. I used NumPy library.

The code below is for understanding what train variable is.
training_data.append([np.array(img), np.array(label)]) 
 train = train_data[:-500]

I have tried to do it two ways.
First i have had the error:
TypeError: 'int'object is not subscriptable

For the second way i have had the error:
ValueError: setting an array element as a sequence

Update: the code, where training data list was create. The train is the slice of training_data
def create_train_data(): 
    training_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)]) 
'train_data.npy', training_data) 

    return training_data 

    train_data = create_train_data() 
    train = train_data[:-500]

There is what print(train) gives

What I have tried:

First way:
X = np.array([i[0] for i in train]).reshape(-1, IMG_SIZE, IMG_SIZE, 1)

Second way:
MyX=np.asarray( train[0])
X = MyX.reshape(-1, IMG_SIZE, IMG_SIZE, 1)
Updated 6-Jun-19 1:01am
Richard MacCutchan 6-Jun-19 3:30am
Add some print statements to your code so you can see exactly what is in train before you try to use it. The code you have shown is incomplete, and we have no idea what data exists in any of the arrays.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100