• Register
1 vote
57 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

Please log in or register to answer this question.

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 19 views
19 views
Problem: Can anyone show me what to do to fix the problem in the broken code above so that it stops throwing an error message? ValueError: setting an array element with a sequence. thanks in advance
asked Mar 24 ummesalma 29.2k points
0 votes
1 answer 24 views
24 views
Problem: Throws this error message: File "mypath\mypythonscript.py", line 3484, in secondfunction RRDuringArray = p.array(UnFilteredDuringExSummaryOfMeansArray,dtype=p.float64)[1:,3] ValueError: setting an array element with a sequence. Can anyone show me what to do to fix the problem ... error message? EDIT: I did a print command to get the contents of the matrix, and this is what it printed out:
asked Feb 18 Mashhoodch 13k points
0 votes
1 answer 2 views
2 views
Problem: Could someone please assist me? > Python valueerror: setting an array element with a sequence.
asked 17 hours ago Isac Christiaan 420 points
1 vote
1 answer 10 views
10 views
Problem: I need a help , How I can fix this : valueerror: setting an array element with a sequence.
asked Mar 13 MUHAMMAD MUNEEB 83k points
0 votes
1 answer 8 views
8 views
Problem: I'll make a submission for a response to my question. Please, I have searched the internet but have not found any useful material, and I am now having trouble continuing my studies.
asked Mar 29 tuhin1 48.9k points
0 votes
1 answer 12 views
12 views
Problem Anyone can help me how can i delete an element from array in c++
asked Mar 27 Subhendu 4.5k points
1 vote
1 answer 9 views
9 views
Problem: How to find the index of an element in a list? Python find the index of an element in a list.
asked Mar 30 PkGuy 23.5k points
0 votes
1 answer 893 views
893 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, 2020 jwilliam 3.9k points
0 votes
1 answer 14 views
14 views
Problem: I want is to display all consecutive sequences from a given array of ints. Finally I want to display the longest one with text. What I tried I sorted the array and found all sequences. I stored the found sequences into a new ArrayList. Below is only a small piece of code, because ... - 1) == myArray[i - 1]) { secuence.add(myArray[i]); } } I tried many different ways, but can't figure out.
asked Apr 24 sumaiya simi 43.9k points
0 votes
1 answer 2 views
2 views
Problem: I will request someone to answer my question Please, I have searched on the web but I got no useful information for this, now I am in difficulty continuing my learning
asked Mar 29 tuhin1 48.9k points