Error while converting a list into a numpy array

0 votes

I have a list

len(list) = 9260  
list[0].shape = (224,224,3)  

Now when I try to convert it to a numpy array, 

x = np.array(list)  

I get the following error:

ValueError: could not broadcast input array from shape (224,224,3) into shape (224,224)  
Jun 14, 2019 in Python by Siara

edited Jun 14, 2019 2,761 views

1 answer to this question.

0 votes
The only possible reason I could think of with this error is that probably one of your list element is not 3 dimensional. Have a closer look at your list, its data structure.
answered Jun 14, 2019 by Rhea
Thanks, @Rhea, that was the exact same issue with my list. The inner array, one element wasn't a 3 dimensional.

Related Questions In Python

0 votes
1 answer

How do I turn a list into numpy array?

Use this line: numpy_array = np.array(list) And printing/displaying the ...READ MORE

answered May 24, 2019 in Python by Isha
835 views
0 votes
1 answer

How do I read CSV data into a record array in NumPy?

Hello @kartik, You can use Numpy's genfromtxt() method to do ...READ MORE

answered Jun 22, 2020 in Python by Niroj
• 82,880 points
3,432 views
+1 vote
1 answer

How to convert a PIL Image into a numpy array?

Hello @kartik, You just need to convert your ...READ MORE

answered Jun 22, 2020 in Python by Niroj
• 82,880 points
4,391 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,348 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
3,905 views
+4 votes
7 answers

Splitting a List into chunks in Python

Here's a generator that yields the chunks ...READ MORE

answered Apr 13, 2018 in Python by Nietzsche's daemon
• 4,260 points
35,283 views
0 votes
2 answers

In Python, how do I read a file line-by-line into a list?

readline function help to  read line in ...READ MORE

answered Jun 21, 2020 in Python by sahil
• 580 points
1,713 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP