• Register
1 vote
17 views

Problem:

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?

10 7 2
6,060 points

1 Answer

1 vote

Answer:

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)

 

11 6 4
34,950 points

Related questions

0 votes
1 answer 474 views
474 views
Problem : I am having below error in a title, and I don't know what's wrong. It was working when I used np.hstack instead of the np.append, but I want to make this faster, so using append. time_list the list of floats heights is the 1d np.array of ... <module> axe_x.append(time_list[np.arange(j+n,j+(time_interval-n))]) TypeError: only integer arrays with one element can be converted to an index
asked Jan 24 jwilliam 3.9k points
0 votes
1 answer 2 views
0 votes
1 answer 30 views
30 views
Problem: Can any one help me in array programming? What happen when an individual element of an array is passed to a method?
asked Feb 22 maddi86 5.4k points
0 votes
2 answers 1.3K views
1.3K views
Problem : I got following rather cryptic error message: the truth value of an array with more than one element is ambiguous. use a.any() or a.all()
asked Nov 18, 2019 peterlaw 6.9k points
0 votes
1 answer 4 views
4 views
What is the difference between array and list in python?
asked Oct 10 sikandar 2.4k points